Skip to content

Commit 7bd1407

Browse files
StringEpsilontimdorr
authored andcommittedApr 20, 2019
matchPath: Fixed exception thrown if path is undefined (#6715)
* matchPath: Fixed exception thrown if `path` is undefined * Match the line below it
1 parent 67df646 commit 7bd1407

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed
 

‎packages/react-router/modules/__tests__/matchPath-test.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { matchPath } from "react-router";
22

33
describe("matchPath", () => {
4+
describe("without path property on params", () => {
5+
it("doesn't throw an exception", () => {
6+
expect(() => {
7+
matchPath("/milkyway/eridani", { hash: "foo" });
8+
}).not.toThrow();
9+
});
10+
});
11+
412
describe('with path="/"', () => {
513
it('returns correct url at "/"', () => {
614
const path = "/";

‎packages/react-router/modules/matchPath.js

+2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ function matchPath(pathname, options = {}) {
3333
const paths = [].concat(path);
3434

3535
return paths.reduce((matched, path) => {
36+
if (!path) return null;
3637
if (matched) return matched;
38+
3739
const { regexp, keys } = compilePath(path, {
3840
end: exact,
3941
strict,

0 commit comments

Comments
 (0)
Please sign in to comment.