Skip to content

Commit

Permalink
handle file path in other cases
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed Nov 3, 2022
1 parent 286df9a commit 5e529c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/gatsby-core-utils/src/__tests__/fetch-remote-file.js
Expand Up @@ -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,
Expand All @@ -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`,
Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby-core-utils/src/filename-utils.ts
Expand Up @@ -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

Expand Down

0 comments on commit 5e529c3

Please sign in to comment.