Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix regression to allow for empty-string paths #6942

Merged
merged 1 commit into from Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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