Skip to content
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
1 change: 1 addition & 0 deletions modules/PatternUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export function compilePattern(pattern) {
* - ** Consumes (greedy) all characters up to the next character
* in the pattern, or to the end of the URL if there is none
*
* The function calls callback(error, matched) when finished.
* The return value is an object with the following properties:
*
* - remainingPathname
Expand Down
13 changes: 13 additions & 0 deletions modules/__tests__/Router-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,19 @@ describe('Router', function () {
})
})

it('handles error that are not valid URI character', function (done) {
const errorSpy = expect.createSpy()

render((
<Router history={createHistory('/%')} onError={errorSpy}>
<Route path="*" />
</Router>
), node, function () {
expect(errorSpy).toHaveBeenCalled()
done()
})
})

})

describe('render prop', function () {
Expand Down
18 changes: 11 additions & 7 deletions modules/matchRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,17 @@ function matchRouteDeep(
// Only try to match the path if the route actually has a pattern, and if
// we're not just searching for potential nested absolute paths.
if (remainingPathname !== null && pattern) {
const matched = matchPattern(pattern, remainingPathname)
if (matched) {
remainingPathname = matched.remainingPathname
paramNames = [ ...paramNames, ...matched.paramNames ]
paramValues = [ ...paramValues, ...matched.paramValues ]
} else {
remainingPathname = null
try {
const matched = matchPattern(pattern, remainingPathname)
if (matched) {
remainingPathname = matched.remainingPathname
paramNames = [ ...paramNames, ...matched.paramNames ]
paramValues = [ ...paramValues, ...matched.paramValues ]
} else {
remainingPathname = null
}
} catch (error) {
callback(error)
}

// By assumption, pattern is non-empty here, which is the prerequisite for
Expand Down