Skip to content

Commit

Permalink
fix regression to allow for empty-string paths
Browse files Browse the repository at this point in the history
  • Loading branch information
heygrady committed Sep 27, 2019
1 parent 375f320 commit 24b95b0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/react-router/modules/__tests__/matchPath-test.js
Expand Up @@ -9,6 +9,23 @@ describe("matchPath", () => {
});
});

describe('with path=""', () => {
it('returns correct url at "/"', () => {
const path = "";
const pathname = "/";
const match = matchPath(pathname, path);
// TODO: why is match.url "/" instead of ""?
expect(match.url).toBe("/");
});

it('returns correct url at "/somewhere/else"', () => {
const path = "";
const pathname = "/somewhere/else";
const match = matchPath(pathname, path);
expect(match.url).toBe("");
});
});

describe('with path="/"', () => {
it('returns correct url at "/"', () => {
const path = "/";
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router/modules/matchPath.js
Expand Up @@ -35,7 +35,7 @@ function matchPath(pathname, options = {}) {
const paths = [].concat(path);

return paths.reduce((matched, path) => {
if (!path) return null;
if (!path && path !== "") return null;
if (matched) return matched;

const { regexp, keys } = compilePath(path, {
Expand Down

0 comments on commit 24b95b0

Please sign in to comment.