Skip to content

Commit

Permalink
matchPath: Fixed exception thrown if path is undefined (#6715)
Browse files Browse the repository at this point in the history
* matchPath: Fixed exception thrown if `path` is undefined

* Match the line below it
  • Loading branch information
StringEpsilon authored and timdorr committed Apr 20, 2019
1 parent 67df646 commit 7bd1407
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/react-router/modules/__tests__/matchPath-test.js
Original file line number Diff line number Diff line change
@@ -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 = "/";
Expand Down
2 changes: 2 additions & 0 deletions packages/react-router/modules/matchPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7bd1407

Please sign in to comment.