Skip to content

Commit

Permalink
Fix handling of patterns that are method names (#3680)
Browse files Browse the repository at this point in the history
  • Loading branch information
taion authored and timdorr committed Jul 29, 2016
1 parent 892d965 commit 62af2ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/PatternUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions modules/__tests__/getParamNames-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([])
})
})
})
4 changes: 4 additions & 0 deletions modules/__tests__/matchPattern-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', '', [], [])
})

})

0 comments on commit 62af2ce

Please sign in to comment.