diff --git a/packages/gatsby/cache-dir/__tests__/find-path.js b/packages/gatsby/cache-dir/__tests__/find-path.js index 769a8964ce74a..da798c7f953d5 100644 --- a/packages/gatsby/cache-dir/__tests__/find-path.js +++ b/packages/gatsby/cache-dir/__tests__/find-path.js @@ -18,6 +18,16 @@ describe(`find-path`, () => { global.__BASE_PATH__ = `/blog` 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`) + }) }) describe(`findMatchPath`, () => { diff --git a/packages/gatsby/cache-dir/find-path.js b/packages/gatsby/cache-dir/find-path.js index 92d7ffed09741..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, __BASE_PATH__) + const trimmedPathname = stripPrefix( + pathname, + decodeURIComponent(__BASE_PATH__) + ) // Remove any hashfragment .split(`#`)[0] // Remove search query