fix: extract full match string to prevent capture group leaking into messages#826
Merged
Merged
Conversation
…messages
The commit_hits_same_numbers rule uses a backreference regex
/(?:([0-9a-f])\1{4,})/ that contains a capture group required for \1.
String.prototype.match() returns [fullMatch, capturedGroup, ...], so
passing the raw RegExpMatchArray to Mustache caused Array.toString() to
render "aaaaa,a" instead of "aaaaa" in celebration messages.
Use matched[0] when building the Mustache context so the template
always receives the full match string regardless of capture groups in
the rule regex. Add a regression test that asserts the rendered message
for a commit ID starting with five repeated hex digits.
🎉 Happy commit!
|
gh-counterPR gate
Repo dashboard
Reported by gh-counter |
Code Metrics Report
Details | | main (45435c8) | #826 (fb20fa7) | +/- |
|---------------------|----------------|----------------|------|
| Coverage | 99.0% | 99.0% | 0.0% |
| Files | 5 | 5 | 0 |
| Lines | 107 | 107 | 0 |
| Covered | 106 | 106 | 0 |
+ | Code to Test Ratio | 1:0.5 | 1:0.5 | +0.0 |
| Code | 1386 | 1408 | +22 |
+ | Test | 758 | 777 | +19 |
- | Test Execution Time | 1s | 2s | +1s |Code coverage of files in pull request scope (96.0% → 96.0%)
Reported by octocov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The
commit_hits_same_numbersrule uses the regex/(?:([0-9a-f])\1{4,})/which contains a capture group required for the backreference\1.String.prototype.match()returns[fullMatch, capturedGroup, ...]when the regex has capture groups, so passing the rawRegExpMatchArrayto Mustache causedArray.toString()to join elements with a comma. For a commit SHA containingaaaaa,{{matched}}expanded to"aaaaa,a"instead of"aaaaa".What changed
src/message_builder.ts: passmatched[0](the full match string) instead of the raw array to the Mustache render contextsrc/message_builder.spec.ts: add a regression test asserting that a commit ID starting with five repeated hex digits renders the match as justaaaaa, notaaaaa,aVerification
All 40 tests pass.
biome checkreports no issues.The capture group in
src/rules.ts:104is intentionally kept — it is still required for\1to work. Only the downstream consumer (message_builder.ts) was changed to discard the captured sub-match.