Skip to content

Commit

Permalink
fix: encodes upload filename urls (#10048)
Browse files Browse the repository at this point in the history
### What?

Previously, upload files urls were not being encoded.

### Why?

As a result, this could lead to discrepancies where upload filenames
with spaces - the spaces would not be encoded as %20 in the URL.

### How?

To address this issue, we simply need to encode the filename of the
upload media.

Fixes #9698
  • Loading branch information
PatrikKozak authored Dec 18, 2024
1 parent f29e633 commit 1446fe4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/payload/src/uploads/getBaseFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type GenerateURLArgs = {
}
const generateURL = ({ collectionSlug, config, filename }: GenerateURLArgs) => {
if (filename) {
return `${config.serverURL || ''}${config.routes.api || ''}/${collectionSlug}/file/${filename}`
return `${config.serverURL || ''}${config.routes.api || ''}/${collectionSlug}/file/${encodeURIComponent(filename)}`
}
return undefined
}
Expand Down

0 comments on commit 1446fe4

Please sign in to comment.