Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot download file with non-ascii filename from remote source #35636

Closed
2 tasks done
cometkim opened this issue May 12, 2022 · 6 comments · Fixed by #35637
Closed
2 tasks done

Cannot download file with non-ascii filename from remote source #35636

cometkim opened this issue May 12, 2022 · 6 comments · Fixed by #35637
Labels
status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. topic: core Relates to Gatsby's core (e.g. page loading, reporter, state machine) type: bug An issue or pull request relating to a bug in Gatsby

Comments

@cometkim
Copy link
Contributor

Preliminary Checks

Description

when I source file nodes via createRemoteFileNode.

The actual saved filename should be a decoded string. otherwise it becomes unavailable if source url is an encoded string.

For example, sourcing a file from a340d817-7e76-4dfd-a704-74b4a526d77c_테스트.txt, its publicURL and actual base on the filesystem is going to be a340d817-7e76-4dfd-a704-74b4a526d77c_%e1%84%90%e1%85%a6%e1%84%89%e1%85%b3%e1%84%90%e1%85%b3.txt

I think publicURL is fine, but filesystem path with encoded base is not useful because typical web servers cannot retrieve it from the publicURL.

Reproduction Link

https://github.com/cometkim/gatsby-remote-file-non-ascii

Steps to Reproduce

  1. yarn install & start gatsby
  2. Open http://localhost:8000/
  3. Click "Can I download file" link

Expected Result

200 Ok, I can see the text content "테스트"

Actual Result

404 Not found.

Environment

System:
    OS: macOS 12.2.1
    CPU: (10) x64 Apple M1 Pro
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.14.0 - /var/folders/z5/shv_7yrx1cg51gkbb8jh9x180000gn/T/yarn--1652323880604-0.0013071866350218286/node
    Yarn: 1.22.17 - /var/folders/z5/shv_7yrx1cg51gkbb8jh9x180000gn/T/yarn--1652323880604-0.0013071866350218286/yarn
    npm: 8.3.1 - ~/.asdf/plugins/nodejs/shims/npm
  Languages:
    Python: 2.7.18 - /usr/bin/python
  Browsers:
    Chrome: 101.0.4951.54
    Safari: 15.3
  npmPackages:
    gatsby: ^4.13.1 => 4.14.0 
    gatsby-plugin-gatsby-cloud: ^4.13.0 => 4.14.0 
    gatsby-plugin-image: ^2.13.0 => 2.14.0 
    gatsby-plugin-manifest: ^4.13.0 => 4.14.0 
    gatsby-plugin-offline: ^5.13.0 => 5.14.0 
    gatsby-plugin-react-helmet: ^5.13.0 => 5.14.0 
    gatsby-plugin-sharp: ^4.13.0 => 4.14.0 
    gatsby-source-filesystem: ^4.13.0 => 4.14.0 
    gatsby-transformer-sharp: ^4.13.0 => 4.14.0

Config Flags

No response

@cometkim cometkim added the type: bug An issue or pull request relating to a bug in Gatsby label May 12, 2022
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label May 12, 2022
@pieh pieh added topic: core Relates to Gatsby's core (e.g. page loading, reporter, state machine) and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels May 16, 2022
@LekoArts LekoArts added the status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. label May 17, 2022
cometkim added a commit to daangn/websites that referenced this issue Jun 21, 2022
@Boronare
Copy link

Boronare commented Oct 28, 2022

change gatsby-source-wordpress/src/steps/source-nodes/reate-nodes/create-remote-file-node/index.js:449 to

  const fileDownloadPromise = pushTask({
    url,
    cache,
    createNode,
    parentNodeId,
    createNodeId,
    auth,
    httpHeaders,
    ext,
    name: decodeURI(name), // << HERE
    limit
  });

will fix the problem.

@Boronare
Copy link

Boronare commented Oct 28, 2022

Ah... sorry... I had same issue while using wordpress, so I modified like that. Is it from helmet? or so? find similar path may fix it I think.
----edit----
found.
around gatsby-source-filesystem/src/create-remote-file-node.js:56

  const filename = await fetchRemoteFile({
    url,
    cache,
    auth,
    httpHeaders,
    ext,
    name: decodeURI(name), // << HERE
  })

@Boronare
Copy link

To get rid of the more fundamental problem
It'll be better to change gatsby-core-utils/src/fetch-remote-file.ts:176

      const downloadPath = createFilePath(finalDirectory, decodeURI(name), ext)

By the way, gatsby-source-wordpress doesn't refer core-utils but use almost same as its code instead...

@cometkim
Copy link
Contributor Author

cometkim commented Nov 1, 2022

@Boronare can you confirm that #35 fixes your problem as well?

@Boronare
Copy link

Boronare commented Nov 2, 2022

@cometkim Well, this approach is opposite to my first approach, if there's 'name' param, getRemoteFileName won't be called.

@cometkim
Copy link
Contributor Author

cometkim commented Nov 2, 2022

Ok I see, that a good catch.

cometkim added a commit to daangn/websites that referenced this issue Feb 21, 2023
cometkim added a commit to daangn/websites that referenced this issue Feb 21, 2023
* [WMAS-46] remove temporal patch code for file downloading

See gatsbyjs/gatsby#35636
Resolves [WMAS-46]

* update lockfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. topic: core Relates to Gatsby's core (e.g. page loading, reporter, state machine) type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
4 participants