diff --git a/modules/PatternUtils.js b/modules/PatternUtils.js index acfc143dc6..551900f97d 100644 --- a/modules/PatternUtils.js +++ b/modules/PatternUtils.js @@ -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 diff --git a/modules/__tests__/Router-test.js b/modules/__tests__/Router-test.js index 4563c23ee5..75e152ff2e 100644 --- a/modules/__tests__/Router-test.js +++ b/modules/__tests__/Router-test.js @@ -276,6 +276,19 @@ describe('Router', function () { }) }) + it('handles error that are not valid URI character', function (done) { + const errorSpy = expect.createSpy() + + render(( + + + + ), node, function () { + expect(errorSpy).toHaveBeenCalled() + done() + }) + }) + }) describe('render prop', function () { diff --git a/modules/matchRoutes.js b/modules/matchRoutes.js index 1f5df6648a..37bde417a2 100644 --- a/modules/matchRoutes.js +++ b/modules/matchRoutes.js @@ -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