Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of patterns that are method names #3680

Merged
merged 1 commit into from
Jul 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case passes against master, but worth asserting here anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you get it to fail against Firefox with 'watch'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not here – matchPattern prepends a / to all patterns to match the pathname.

The failing test case is the getParamsName one, which currently would fail on all browsers.

assertMatch('toString', '/toString', '', [], [])
})

})