fix: #538 escape regex metacharacters in Fbe.mask_to_regex#540
Conversation
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
left a comment
There was a problem hiding this comment.
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.
|
@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! 💪 |
|
@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. |
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 likezold-io/blog.zold.*therefore matched siblings such aszold-io/blogXzoldYio, and a literal exclusion like-zold-io/blog.zold.iodropped 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.escapeand then turns the escaped literal\*back into.*so wildcards keep working. Onlylib/fbe/unmask_repos.rb:27is touched, plus three minitest cases intest/fbe/test_unmask_repos.rbcovering 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.rbruns the seven non-skipped tests with 24 assertions and 0 failures;rubocop lib/fbe/unmask_repos.rb test/fbe/test_unmask_repos.rb --format simplereports no offenses. The widerrake testshows 10 pre-existingFbe::OffQuotaerrors intest/fbe/test_octo.rband the middleware suites that also reproduce on a cleanmastercheckout in this sandbox, so they are not introduced by this commit; GitHub CI onmasteris currently green, which matches the pre-existing-vs-environment split.Closes #538