From 60f18b7deda9382c264186d073aeccc456328ce0 Mon Sep 17 00:00:00 2001 From: Dan Kirkham Date: Mon, 5 Apr 2021 09:43:46 +0100 Subject: [PATCH 1/4] Decode base path --- packages/gatsby/cache-dir/find-path.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/cache-dir/find-path.js b/packages/gatsby/cache-dir/find-path.js index 92d7ffed09741..c630cd338cca7 100644 --- a/packages/gatsby/cache-dir/find-path.js +++ b/packages/gatsby/cache-dir/find-path.js @@ -8,7 +8,7 @@ let matchPaths = [] const trimPathname = rawPathname => { const pathname = decodeURIComponent(rawPathname) // Remove the pathPrefix from the pathname. - const trimmedPathname = stripPrefix(pathname, __BASE_PATH__) + const trimmedPathname = stripPrefix(pathname, decodeURIComponent(__BASE_PATH__)) // Remove any hashfragment .split(`#`)[0] // Remove search query From d322a07ccabaacd703419f0e3cebf42c81b31bbc Mon Sep 17 00:00:00 2001 From: Dan Kirkham Date: Mon, 5 Apr 2021 09:53:18 +0100 Subject: [PATCH 2/4] Formatting --- packages/gatsby/cache-dir/find-path.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/gatsby/cache-dir/find-path.js b/packages/gatsby/cache-dir/find-path.js index c630cd338cca7..64987d4208122 100644 --- a/packages/gatsby/cache-dir/find-path.js +++ b/packages/gatsby/cache-dir/find-path.js @@ -8,7 +8,10 @@ let matchPaths = [] const trimPathname = rawPathname => { const pathname = decodeURIComponent(rawPathname) // Remove the pathPrefix from the pathname. - const trimmedPathname = stripPrefix(pathname, decodeURIComponent(__BASE_PATH__)) + const trimmedPathname = stripPrefix( + pathname, + decodeURIComponent(__BASE_PATH__) + ) // Remove any hashfragment .split(`#`)[0] // Remove search query From 58876def182caf6557331bf268a71ae6f2e7c69b Mon Sep 17 00:00:00 2001 From: Dan Kirkham Date: Mon, 5 Apr 2021 11:17:28 +0100 Subject: [PATCH 3/4] Add test for encoded basepath --- packages/gatsby/cache-dir/__tests__/find-path.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/gatsby/cache-dir/__tests__/find-path.js b/packages/gatsby/cache-dir/__tests__/find-path.js index 769a8964ce74a..cda6246881cdd 100644 --- a/packages/gatsby/cache-dir/__tests__/find-path.js +++ b/packages/gatsby/cache-dir/__tests__/find-path.js @@ -18,6 +18,11 @@ describe(`find-path`, () => { global.__BASE_PATH__ = `/blog` expect(cleanPath(`/blog/mypath`)).toBe(`/mypath`) }) + + it(`strip out an encoded basePrefix`, () => { + global.__BASE_PATH__ = encodeURIComponent(`/тест`) + expect(cleanPath(`/тест/mypath`)).toBe(`/mypath`) + }) }) describe(`findMatchPath`, () => { From 89ce592882f9ef746ffda5dadfdd0a316247c0b2 Mon Sep 17 00:00:00 2001 From: Dan Kirkham Date: Mon, 12 Apr 2021 15:16:11 +0100 Subject: [PATCH 4/4] Add another test --- packages/gatsby/cache-dir/__tests__/find-path.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/gatsby/cache-dir/__tests__/find-path.js b/packages/gatsby/cache-dir/__tests__/find-path.js index cda6246881cdd..da798c7f953d5 100644 --- a/packages/gatsby/cache-dir/__tests__/find-path.js +++ b/packages/gatsby/cache-dir/__tests__/find-path.js @@ -19,6 +19,11 @@ describe(`find-path`, () => { expect(cleanPath(`/blog/mypath`)).toBe(`/mypath`) }) + it(`strip out a complex basePrefix`, () => { + global.__BASE_PATH__ = `/test/blog` + expect(cleanPath(`/test/blog/new`)).toBe(`/new`) + }) + it(`strip out an encoded basePrefix`, () => { global.__BASE_PATH__ = encodeURIComponent(`/тест`) expect(cleanPath(`/тест/mypath`)).toBe(`/mypath`)