Skip to content

Commit ca084c0

Browse files
committed
add reproduction case with regex with global flag
1 parent d578c7e commit ca084c0

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/__tests__/matches.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ test('matchers accept regex', () => {
1515
expect(fuzzyMatches('ABC', node, /ABC/, normalizer)).toBe(true)
1616
})
1717

18+
// https://stackoverflow.com/questions/1520800/why-does-a-regexp-with-global-flag-give-wrong-results
19+
test('matchers recreate regex to prevent global mistakes', () => {
20+
const regex = /ABC/g
21+
expect(matches('ABC', node, regex, normalizer)).toBe(true)
22+
// without recreation of the regexp this would be false
23+
expect(fuzzyMatches('ABC', node, regex, normalizer)).toBe(true)
24+
})
25+
1826
test('matchers accept functions', () => {
1927
expect(matches('ABC', node, text => text === 'ABC', normalizer)).toBe(true)
2028
expect(fuzzyMatches('ABC', node, text => text === 'ABC', normalizer)).toBe(

0 commit comments

Comments
 (0)