From 83d0bf56caa0d6f3661904e8d234869e92995ab9 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Thu, 28 Jul 2016 17:58:52 -0400 Subject: [PATCH] Fix handling of patterns that are method names --- modules/PatternUtils.js | 4 ++-- modules/__tests__/getParamNames-test.js | 6 ++++++ modules/__tests__/matchPattern-test.js | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) 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', '', [], []) + }) + })