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

Filenames in upload URLs are not encoded #9698

Closed
cbratschi opened this issue Dec 3, 2024 · 2 comments · Fixed by #10048
Closed

Filenames in upload URLs are not encoded #9698

cbratschi opened this issue Dec 3, 2024 · 2 comments · Fixed by #10048
Assignees

Comments

@cbratschi
Copy link

Describe the Bug

Payload and its cloud storage adapters create URLs for uploaded media files. Filenames are stored in UTF-8 but they are never encoded in the URLs:

const generateURL = ({ collectionSlug, config, filename }: GenerateURLArgs) => {
  if (filename) {
    return `${config.serverURL || ''}${config.routes.api || ''}/${collectionSlug}/file/${filename}`
  }
  return undefined
}

https://github.com/payloadcms/payload/blob/main/packages/payload/src/uploads/getBaseFields.ts#L15

This code should be changed to:

const generateURL = ({ collectionSlug, config, filename }: GenerateURLArgs) => {
  if (filename) {
    return `${config.serverURL || ''}${config.routes.api || ''}/${collectionSlug}/file/${encodeURIComponent(filename)}`
  }
  return undefined
}

We use encodeURIComponent() in our own GridFS plugin and this works fine. We detected this error while reviewing the Payload 3.x code changes.

Link to the code that reproduces this issue

https://github.com/cbratschi/payload

Reproduction Steps

Upload file with spaces, the spaces are not encoded as %20 in the URL.

Which area(s) are affected? (Select all that apply)

area: core, plugin: cloud-storage

Environment Info

Binaries:
  Node: 22.9.0
  npm: 10.8.3
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  payload: 3.2.2
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:23 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6031
  Available memory (MB): 65536
  Available CPU cores: 16
@cbratschi cbratschi added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Dec 3, 2024
@PatrikKozak PatrikKozak self-assigned this Dec 18, 2024
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Dec 18, 2024
Copy link
Contributor

🚀 This is included in version v3.9.0

Copy link
Contributor

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants