diff --git a/modules/PatternUtils.js b/modules/PatternUtils.js index 551900f97d..3b8e56ea4e 100644 --- a/modules/PatternUtils.js +++ b/modules/PatternUtils.js @@ -49,10 +49,10 @@ function _compilePattern(pattern) { } } -const CompiledPatternsCache = {} +const CompiledPatternsCache = Object.create(null) export function compilePattern(pattern) { - if (!(pattern in CompiledPatternsCache)) + if (!CompiledPatternsCache[pattern]) CompiledPatternsCache[pattern] = _compilePattern(pattern) return CompiledPatternsCache[pattern] diff --git a/modules/__tests__/getParamNames-test.js b/modules/__tests__/getParamNames-test.js index 661c5b085c..ee068be2f3 100644 --- a/modules/__tests__/getParamNames-test.js +++ b/modules/__tests__/getParamNames-test.js @@ -19,4 +19,10 @@ describe('getParamNames', function () { expect(getParamNames('/files/*.jpg')).toEqual([ 'splat' ]) }) }) + + describe('when a pattern has the same name as a built-in method', function () { + it('should work', function () { + expect(getParamNames('toString')).toEqual([]) + }) + }) }) diff --git a/modules/__tests__/matchPattern-test.js b/modules/__tests__/matchPattern-test.js index 236d952576..30940f3bd5 100644 --- a/modules/__tests__/matchPattern-test.js +++ b/modules/__tests__/matchPattern-test.js @@ -41,4 +41,8 @@ describe('matchPattern', function () { assertMatch('/**/*.jpg', '/files/path/to/file.jpg', '', [ 'splat', 'splat' ], [ 'files/path/to', 'file' ]) }) + it('works with patterns that match built-in names', function () { + assertMatch('toString', '/toString', '', [], []) + }) + })