From 2fc814bcbe89f91ca0cd8e3b3e66f87045a7b3e0 Mon Sep 17 00:00:00 2001 From: Sibelius Seraphini Date: Thu, 24 May 2018 14:25:09 -0300 Subject: [PATCH 1/4] test(core): add failing test to generatePath, see #6171 --- .../modules/__tests__/generatePath-test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/react-router/modules/__tests__/generatePath-test.js b/packages/react-router/modules/__tests__/generatePath-test.js index 3f84a78eca..6ecbd73bf5 100644 --- a/packages/react-router/modules/__tests__/generatePath-test.js +++ b/packages/react-router/modules/__tests__/generatePath-test.js @@ -53,4 +53,16 @@ describe("generatePath", () => { expect(generated).toBe("/"); }); }); + + describe('simple pattern="/view/:id"', () => { + it("handle = on params", () => { + const pattern = "/view/:id"; + const params = { id: "Q29tcGxhaW50OjVhZjFhMDg0MzhjMTk1MThiMTdlOTQ2Yg==" }; + + const generated = generatePath(pattern, path); + expect(generated).toBe( + "/view/Q29tcGxhaW50OjVhZjFhMDg0MzhjMTk1MThiMTdlOTQ2Yg==" + ); + }); + }); }); From 77447606cc417604458dd50498878fb5b1e24d69 Mon Sep 17 00:00:00 2001 From: Sibelius Seraphini Date: Thu, 24 May 2018 14:29:11 -0300 Subject: [PATCH 2/4] fix(typo): fix typo on test --- packages/react-router/modules/__tests__/generatePath-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-router/modules/__tests__/generatePath-test.js b/packages/react-router/modules/__tests__/generatePath-test.js index 6ecbd73bf5..d07404ed31 100644 --- a/packages/react-router/modules/__tests__/generatePath-test.js +++ b/packages/react-router/modules/__tests__/generatePath-test.js @@ -59,7 +59,7 @@ describe("generatePath", () => { const pattern = "/view/:id"; const params = { id: "Q29tcGxhaW50OjVhZjFhMDg0MzhjMTk1MThiMTdlOTQ2Yg==" }; - const generated = generatePath(pattern, path); + const generated = generatePath(pattern, params); expect(generated).toBe( "/view/Q29tcGxhaW50OjVhZjFhMDg0MzhjMTk1MThiMTdlOTQ2Yg==" ); From 92170525fad56f0f27c53146142163d324a88c3f Mon Sep 17 00:00:00 2001 From: Tim Dorr Date: Thu, 24 May 2018 15:29:20 -0400 Subject: [PATCH 3/4] Use the pretty option. --- packages/react-router/modules/generatePath.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-router/modules/generatePath.js b/packages/react-router/modules/generatePath.js index 5022df4a08..7f1ffe8771 100644 --- a/packages/react-router/modules/generatePath.js +++ b/packages/react-router/modules/generatePath.js @@ -10,7 +10,7 @@ const compileGenerator = pattern => { if (cache[pattern]) return cache[pattern]; - const compiledGenerator = pathToRegexp.compile(pattern); + const compiledGenerator = pathToRegexp.compile(pattern, { pretty: true }); if (cacheCount < cacheLimit) { cache[pattern] = compiledGenerator; From 926b618026b0422707732e0cac5719a32591b004 Mon Sep 17 00:00:00 2001 From: Paul Sherman Date: Fri, 25 May 2018 13:57:39 -0500 Subject: [PATCH 4/4] Pretty in compiled function --- packages/react-router/modules/generatePath.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-router/modules/generatePath.js b/packages/react-router/modules/generatePath.js index 7f1ffe8771..40db6d6a06 100644 --- a/packages/react-router/modules/generatePath.js +++ b/packages/react-router/modules/generatePath.js @@ -10,7 +10,7 @@ const compileGenerator = pattern => { if (cache[pattern]) return cache[pattern]; - const compiledGenerator = pathToRegexp.compile(pattern, { pretty: true }); + const compiledGenerator = pathToRegexp.compile(pattern); if (cacheCount < cacheLimit) { cache[pattern] = compiledGenerator; @@ -28,7 +28,7 @@ const generatePath = (pattern = "/", params = {}) => { return pattern; } const generator = compileGenerator(pattern); - return generator(params); + return generator(params, { pretty: true }); }; export default generatePath;