Skip to content

fix: #538 escape regex metacharacters in Fbe.mask_to_regex#540

Merged
yegor256 merged 1 commit into
zerocracy:masterfrom
edmoffo:538-mask-to-regex-escape
Jun 8, 2026
Merged

fix: #538 escape regex metacharacters in Fbe.mask_to_regex#540
yegor256 merged 1 commit into
zerocracy:masterfrom
edmoffo:538-mask-to-regex-escape

Conversation

@edmoffo

@edmoffo edmoffo commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Fbe.mask_to_regex used to interpolate the mask straight into the pattern and only translate *. Every other regex metacharacter (a dot, a plus, parentheses, etc.) survived unchanged and was reinterpreted as an operator at match time. A wildcard like zold-io/blog.zold.* therefore matched siblings such as zold-io/blogXzoldYio, and a literal exclusion like -zold-io/blog.zold.io dropped repositories whose names merely shared that skeleton. Issue #538 lays the failure out file-by-file.

The change routes both halves of the mask through Regexp.escape and then turns the escaped literal \* back into .* so wildcards keep working. Only lib/fbe/unmask_repos.rb:27 is touched, plus three minitest cases in test/fbe/test_unmask_repos.rb covering a literal dot, a non-dot metacharacter (+), and the wildcard-still-expands path.

Local checks against ruby 3.3.6 on linux: bundle exec ruby -Itest test/fbe/test_unmask_repos.rb runs the seven non-skipped tests with 24 assertions and 0 failures; rubocop lib/fbe/unmask_repos.rb test/fbe/test_unmask_repos.rb --format simple reports no offenses. The wider rake test shows 10 pre-existing Fbe::OffQuota errors in test/fbe/test_octo.rb and the middleware suites that also reproduce on a clean master checkout in this sandbox, so they are not introduced by this commit; GitHub CI on master is currently green, which matches the pre-existing-vs-environment split.

Closes #538

Fbe.mask_to_regex used to interpolate the mask straight into a Regexp,
escaping only '*'. Any other metacharacter inside the mask (dot, plus,
parentheses, etc.) was reinterpreted as a regex operator, so a wildcard
like 'zold-io/blog.zold.*' matched siblings such as 'zold-io/blogXzoldYio'
because the dots became wildcards too.

Pass org and repo through Regexp.escape first, then turn the escaped
literal '\*' back into '.*' so wildcards keep working.

Closes zerocracy#538

@kreinba kreinba left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Routes both org and repo through Regexp.escape and then re-expands only the escaped asterisks via gsub('\\', '.'), which is exactly the minimal fix #538 prescribes. The three new tests pin the three behavioral paths: dot stays literal, plus stays literal, wildcard still matches. The anchoring concern from #474 is separately tracked in #495 as the issue body itself notes, and is out of scope here. CI is green.

@0crat

0crat commented Jun 4, 2026

Copy link
Copy Markdown

@kreinba Thanks for the review! You've earned +6 points for this contribution. Here's the breakdown per our work policy: +18 base points for authoring the review, -8 points deducted due to no comments being posted during the review process, and -4 points deducted for having only 22 hits-of-code (below the 24 minimum threshold). Your running score is +1550 – keep up the great work and don't forget to check your Zerocracy account for updates! 💪

@yegor256 yegor256 merged commit 7c52793 into zerocracy:master Jun 8, 2026
10 checks passed
@0crat

0crat commented Jun 8, 2026

Copy link
Copy Markdown

@edmoffo Thanks for the contribution! You've earned +20 points following our work policy: +24 as the base award, then -4 deducted for contributing fewer than 30 hits-of-code (you had 22). To maximize your bonus next time, aim for 30+ hits-of-code to avoid this penalty. Keep them coming! Your running score is +1871; don't forget to check your Zerocracy account too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants