From 7bd1407803ba8fbec8283f12a27128b8bd4bde75 Mon Sep 17 00:00:00 2001 From: StringEpsilon Date: Sat, 20 Apr 2019 20:30:14 +0200 Subject: [PATCH] matchPath: Fixed exception thrown if `path` is undefined (#6715) * matchPath: Fixed exception thrown if `path` is undefined * Match the line below it --- packages/react-router/modules/__tests__/matchPath-test.js | 8 ++++++++ packages/react-router/modules/matchPath.js | 2 ++ 2 files changed, 10 insertions(+) diff --git a/packages/react-router/modules/__tests__/matchPath-test.js b/packages/react-router/modules/__tests__/matchPath-test.js index 7c91d2c3fd..4718690ac4 100644 --- a/packages/react-router/modules/__tests__/matchPath-test.js +++ b/packages/react-router/modules/__tests__/matchPath-test.js @@ -1,6 +1,14 @@ import { matchPath } from "react-router"; describe("matchPath", () => { + describe("without path property on params", () => { + it("doesn't throw an exception", () => { + expect(() => { + matchPath("/milkyway/eridani", { hash: "foo" }); + }).not.toThrow(); + }); + }); + describe('with path="/"', () => { it('returns correct url at "/"', () => { const path = "/"; diff --git a/packages/react-router/modules/matchPath.js b/packages/react-router/modules/matchPath.js index b0be891a2d..773c238ae9 100644 --- a/packages/react-router/modules/matchPath.js +++ b/packages/react-router/modules/matchPath.js @@ -33,7 +33,9 @@ function matchPath(pathname, options = {}) { const paths = [].concat(path); return paths.reduce((matched, path) => { + if (!path) return null; if (matched) return matched; + const { regexp, keys } = compilePath(path, { end: exact, strict,