Skip to content

Commit 62af2ce

Browse files
taiontimdorr
authored andcommitted
Fix handling of patterns that are method names (#3680)
1 parent 892d965 commit 62af2ce

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

modules/PatternUtils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ function _compilePattern(pattern) {
4949
}
5050
}
5151

52-
const CompiledPatternsCache = {}
52+
const CompiledPatternsCache = Object.create(null)
5353

5454
export function compilePattern(pattern) {
55-
if (!(pattern in CompiledPatternsCache))
55+
if (!CompiledPatternsCache[pattern])
5656
CompiledPatternsCache[pattern] = _compilePattern(pattern)
5757

5858
return CompiledPatternsCache[pattern]

modules/__tests__/getParamNames-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ describe('getParamNames', function () {
1919
expect(getParamNames('/files/*.jpg')).toEqual([ 'splat' ])
2020
})
2121
})
22+
23+
describe('when a pattern has the same name as a built-in method', function () {
24+
it('should work', function () {
25+
expect(getParamNames('toString')).toEqual([])
26+
})
27+
})
2228
})

modules/__tests__/matchPattern-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@ describe('matchPattern', function () {
4141
assertMatch('/**/*.jpg', '/files/path/to/file.jpg', '', [ 'splat', 'splat' ], [ 'files/path/to', 'file' ])
4242
})
4343

44+
it('works with patterns that match built-in names', function () {
45+
assertMatch('toString', '/toString', '', [], [])
46+
})
47+
4448
})

0 commit comments

Comments
 (0)