fix(storage): percent-encode object key in multipart fallback URL#4872
Conversation
buildObjectFallbackUrl built the object URL from a raw key. Keys with spaces or reserved characters (and the pre-existing AWS branch) would produce a structurally invalid location. Encode the key per path segment (preserving '/' separators) across all branches (AWS, custom path-style, virtual-hosted).
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview New unit tests cover Reviewed by Cursor Bugbot for commit 3383635. Configure here. |
Greptile SummaryThis PR fixes
Confidence Score: 5/5Safe to merge — the change is narrowly scoped to the fallback URL builder and does not touch the actual S3 upload path or the /api/files/serve serving path. The fix is a 3-line addition inside a single private helper. All three return branches are covered by new tests, mock state is reset in beforeEach so tests are order-independent, and the location field is explicitly documented as informational — serving continues to use the separately-encoded path field unchanged. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["completeS3MultipartUpload(key, uploadId, parts)"] --> B["s3Client.send(CompleteMultipartUploadCommand)"]
B --> C{response.Location present?}
C -- Yes --> D["use response.Location directly"]
C -- No --> E["buildObjectFallbackUrl(bucket, region, key)"]
E --> F["encodedKey = key.split('/').map(encodeURIComponent).join('/')"]
F --> G{S3_CONFIG.endpoint set?}
G -- No --> H["https://bucket.s3.region.amazonaws.com/encodedKey"]
G -- Yes --> I{forcePathStyle?}
I -- Yes --> J["base/bucket/encodedKey (path-style)"]
I -- No --> K["bucket.hostname/encodedKey (virtual-hosted)"]
D & H & J & K --> L["return { location, path, key }"]
Reviews (3): Last reviewed commit: "test(storage): cover multipart fallback ..." | Re-trigger Greptile |
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 16fc733. Configure here.
…MinIO path-style, key encoding)
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 3383635. Configure here.
Summary
buildObjectFallbackUrlconstructed the objectlocationfrom a raw key. A key containing spaces or reserved characters (+,?,#) — or the pre-existing AWS branch — would yield a structurally invalid URL/separators) across all branches: AWS virtual-hosted, custom path-style, and custom virtual-hosted (R2)Context
Addresses a Greptile review comment on the v0.6.102 release PR (#4871). Not currently triggerable — keys are generated as
kb/<uuid>-<sanitizeFileName(name)>andsanitizeFileNamestrips everything except[a-zA-Z0-9.-], so only/can appear today. This is a robustness fix that future-proofs thelocationvalue and corrects the long-standing AWS branch.Type of Change
Testing
bun run scripts/check-api-validation-contracts.tspasses; biome cleanlocationis informational (serving uses the encodedpath+/api/files/serve), so no behavior change for existing valid keysChecklist