Skip to content

Commit 5e529c3

Browse files
committed
handle file path in other cases
1 parent 286df9a commit 5e529c3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/gatsby-core-utils/src/__tests__/fetch-remote-file.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ describe(`fetch-remote-file`, () => {
349349
expect(gotStream).toBeCalledTimes(1)
350350
})
351351

352-
it(`downloads and create a jpg file for file with non-ascii filename`, async () => {
352+
it(`downloads and create a jpg file for file with non-ascii url`, async () => {
353353
const filePath = await fetchRemoteFile({
354354
url: `http://external.com/${encodeURIComponent(`개`)}.jpg`,
355355
cache,
@@ -362,6 +362,20 @@ describe(`fetch-remote-file`, () => {
362362
expect(gotStream).toBeCalledTimes(1)
363363
})
364364

365+
it(`downloads and create a jpg file for file with non-ascii filename`, async () => {
366+
const filePath = await fetchRemoteFile({
367+
url: `http://external.com/dog.jpg`,
368+
name: `${encodeURIComponent(`개`)}.jpg`,
369+
cache,
370+
})
371+
372+
expect(path.basename(filePath)).toBe(`개.jpg`)
373+
expect(getFileSize(filePath)).resolves.toBe(
374+
await getFileSize(path.join(__dirname, `./fixtures/dog-thumbnail.jpg`))
375+
)
376+
expect(gotStream).toBeCalledTimes(1)
377+
})
378+
365379
it(`downloads and create a jpg file for unknown extension`, async () => {
366380
const filePath = await fetchRemoteFile({
367381
url: `http://external.com/dog`,

packages/gatsby-core-utils/src/filename-utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export function createFilePath(
5252
filename: string,
5353
ext: string
5454
): string {
55+
directory = decodeURIComponent(directory)
56+
filename = decodeURIComponent(filename)
57+
5558
const purgedFileName = filename.replace(filenamePurgeRegex, `-`)
5659
const shouldAddHash = purgedFileName !== filename
5760

0 commit comments

Comments
 (0)