Skip to content

Commit eada495

Browse files
ademczukclaude
andauthored
fix: reset regex state in hasEditProposals (#7)
The module-level regexes use the /g flag (required by matchAll in parseEditProposals). However, RegExp.prototype.test() on a global regex advances lastIndex, so consecutive calls to hasEditProposals with the same input alternate between true and false. Reset lastIndex to 0 before each test call. Added a regression test that verifies consecutive calls return consistent results. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f1d174a commit eada495

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

__tests__/edit-parser.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,11 @@ describe('hasEditProposals', () => {
8484
it('returns false for plain text', () => {
8585
expect(hasEditProposals('no code here')).toBe(false)
8686
})
87+
88+
it('returns consistent results on consecutive calls', () => {
89+
const text = '[EDIT foo.ts]\n```\ncode\n```'
90+
expect(hasEditProposals(text)).toBe(true)
91+
expect(hasEditProposals(text)).toBe(true)
92+
expect(hasEditProposals(text)).toBe(true)
93+
})
8794
})

lib/edit-parser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,7 @@ export function parseEditProposals(text: string): EditProposal[] {
7373
}
7474

7575
export function hasEditProposals(text: string): boolean {
76+
EDIT_MARKER_RE.lastIndex = 0
77+
FENCED_WITH_PATH_RE.lastIndex = 0
7678
return EDIT_MARKER_RE.test(text) || FENCED_WITH_PATH_RE.test(text)
7779
}

0 commit comments

Comments
 (0)