Skip to content

Commit a0db8bf

Browse files
committed
Merge branch 'dev' of https://github.com/brookslybrand/react-router into brookslybrand-dev
2 parents 8853f78 + cfd1a18 commit a0db8bf

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

packages/react-router/__tests__/path-matching-test.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,23 @@ describe("path matching with a basename", () => {
179179
});
180180

181181
describe("path matching with splats", () => {
182-
test("splat after /", () => {
182+
describe("splat after /", () => {
183183
let routes = [{ path: "users/:id/files/*" }];
184184
let match = matchRoutes(routes, "/users/mj/files/secrets.md");
185185

186-
expect(match).not.toBeNull();
187-
expect(match[0]).toMatchObject({
188-
params: { id: "mj", "*": "secrets.md" },
189-
pathname: "/users/mj/files"
186+
it("finds the correct match", () => {
187+
expect(match).not.toBeNull();
188+
expect(match[0]).toMatchObject({
189+
pathname: "/users/mj/files",
190+
params: { id: "mj", "*": "secrets.md" }
191+
});
192+
});
193+
194+
describe("when other characters come before the /", () => {
195+
it("does not find a match", () => {
196+
let match = matchRoutes(routes, "/users/mj/filesssss/secrets.md");
197+
expect(match).toBeNull();
198+
});
190199
});
191200
});
192201

packages/react-router/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ export function matchPath(
908908
let matchedPathname = match[1];
909909
let values = match.slice(2);
910910
let params = paramNames.reduce((memo, paramName, index) => {
911-
memo[paramName] = safelyDecodeURIComponent(values[index], paramName);
911+
memo[paramName] = safelyDecodeURIComponent(values[index] || "", paramName);
912912
return memo;
913913
}, {} as Params);
914914

@@ -941,10 +941,11 @@ function compilePath(
941941

942942
if (path.endsWith("*")) {
943943
if (path.endsWith("/*")) {
944-
source += "\\/?"; // Don't include the / in params['*']
944+
source += "(?:\\/(.+)|\\/?)"; // Don't include the / in params['*']
945+
} else {
946+
source += "(.*)";
945947
}
946948
keys.push("*");
947-
source += "(.*)";
948949
} else if (end) {
949950
source += "\\/?";
950951
}

0 commit comments

Comments
 (0)