Skip to content

fix: extract full match string to prevent capture group leaking into messages#826

Merged
kitsuyui merged 1 commit into
mainfrom
fix/commit-hits-same-numbers-capture-group
May 20, 2026
Merged

fix: extract full match string to prevent capture group leaking into messages#826
kitsuyui merged 1 commit into
mainfrom
fix/commit-hits-same-numbers-capture-group

Conversation

@kitsuyui
Copy link
Copy Markdown
Owner

Why

The commit_hits_same_numbers rule 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 raw RegExpMatchArray to Mustache caused Array.toString() to join elements with a comma. For a commit SHA containing aaaaa, {{matched}} expanded to "aaaaa,a" instead of "aaaaa".

What changed

  • src/message_builder.ts: pass matched[0] (the full match string) instead of the raw array to the Mustache render context
  • src/message_builder.spec.ts: add a regression test asserting that a commit ID starting with five repeated hex digits renders the match as just aaaaa, not aaaaa,a

Verification

All 40 tests pass. biome check reports no issues.

The capture group in src/rules.ts:104 is intentionally kept — it is still required for \1 to work. Only the downstream consumer (message_builder.ts) was changed to discard the captured sub-match.

…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.
@github-actions
Copy link
Copy Markdown

🎉 Happy commit!

@github-actions
Copy link
Copy Markdown

gh-counter

PR gate

Removed Added +/-
TODO/FIXME 0 0 0

Repo dashboard

main (45435c8) #826 (fb20fa7) +/-
TODO/FIXME 0 0 0

Reported by gh-counter

@github-actions
Copy link
Copy Markdown

Code Metrics Report

main (45435c8) #826 (fb20fa7) +/-
Coverage 99.0% 99.0% 0.0%
Code to Test Ratio 1:0.5 1:0.5 +0.0
Test Execution Time 1s 2s +1s
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%)

Files Coverage +/- Status
src/message_builder.ts 96.0% 0.0% modified

Reported by octocov

@kitsuyui kitsuyui merged commit 5c059d6 into main May 20, 2026
5 checks passed
@kitsuyui kitsuyui deleted the fix/commit-hits-same-numbers-capture-group branch May 20, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant