diff --git a/packages/gatsby-core-utils/src/__tests__/fetch-remote-file.js b/packages/gatsby-core-utils/src/__tests__/fetch-remote-file.js index 5cbf985fcce67..ea60474c2c72a 100644 --- a/packages/gatsby-core-utils/src/__tests__/fetch-remote-file.js +++ b/packages/gatsby-core-utils/src/__tests__/fetch-remote-file.js @@ -349,7 +349,7 @@ describe(`fetch-remote-file`, () => { expect(gotStream).toBeCalledTimes(1) }) - it(`downloads and create a jpg file for file with non-ascii filename`, async () => { + it(`downloads and create a jpg file for file with non-ascii url`, async () => { const filePath = await fetchRemoteFile({ url: `http://external.com/${encodeURIComponent(`개`)}.jpg`, cache, @@ -362,6 +362,20 @@ describe(`fetch-remote-file`, () => { expect(gotStream).toBeCalledTimes(1) }) + it(`downloads and create a jpg file for file with non-ascii filename`, async () => { + const filePath = await fetchRemoteFile({ + url: `http://external.com/dog.jpg`, + name: `${encodeURIComponent(`개`)}.jpg`, + cache, + }) + + expect(path.basename(filePath)).toBe(`개.jpg`) + expect(getFileSize(filePath)).resolves.toBe( + await getFileSize(path.join(__dirname, `./fixtures/dog-thumbnail.jpg`)) + ) + expect(gotStream).toBeCalledTimes(1) + }) + it(`downloads and create a jpg file for unknown extension`, async () => { const filePath = await fetchRemoteFile({ url: `http://external.com/dog`, diff --git a/packages/gatsby-core-utils/src/filename-utils.ts b/packages/gatsby-core-utils/src/filename-utils.ts index 03cc37d07b613..463a2bea50c70 100644 --- a/packages/gatsby-core-utils/src/filename-utils.ts +++ b/packages/gatsby-core-utils/src/filename-utils.ts @@ -52,6 +52,9 @@ export function createFilePath( filename: string, ext: string ): string { + directory = decodeURIComponent(directory) + filename = decodeURIComponent(filename) + const purgedFileName = filename.replace(filenamePurgeRegex, `-`) const shouldAddHash = purgedFileName !== filename