Repository navigation
fix(acp): decode URL-encoded attachment filenames - #59793
andreivince wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
There was a problem hiding this comment.
The fix works. I ran promptContentToParts and the replay conversion on the base and on this branch:
file:///tmp/photo%201.pngnow gives the namephoto 1.pnginstead ofphoto%201.png.- Replay now produces
photo%201.pnginstead of the double-encodedphoto%25201.png. - Zed
?path=values are unchanged, and a malformed escape falls back to the raw segment.
The updated wire test fails on the base and passes here, and all 100 ACP tests pass.
The public API is unchanged.
One non-blocking point: an encoded separator in a remote URI is decoded into the filename (see the inline comment).
| const pathname = url.protocol === "zed:" && url.searchParams.get("path") | ||
| if (pathname) return path.basename(pathname) || undefined | ||
| const filename = path.basename(url.pathname) | ||
| return Result.try(() => decodeURIComponent(filename)).pipe(Result.getOrElse(() => filename)) || undefined |
There was a problem hiding this comment.
Decoding after basename means an encoded separator becomes part of the name. For example, https://e.com/a%2Fb.png gives a/b.png (and %5C gives a backslash). On replay, pathToFileURL(part.filename) then turns that into a URI for a nested path, …/a/b.png, which points somewhere the file never was. It's only used for display and the replay URI, so this isn't blocking. Still, running path.basename again after decoding (or replacing / and \) would keep the name a single segment. The test could then expect cover image.png instead of project/cover image.png.
There was a problem hiding this comment.
The new commit fixes the earlier point. After decoding, the name goes through path.win32.basename, so an encoded / or \ no longer ends up in the filename or turns into a nested path on replay. I re-ran the #59792 reproduction on the base and this branch:
- Filenames are now
photo 1.pngandcafé #1.bin. - Replay URIs are no longer double-encoded.
- Zed
?path=values and the fallback for malformed escapes behave as before.
All 100 ACP tests pass. The public API is unchanged. Nothing else to raise.
Issue for this PR
Closes #59792
Type of change
What does this PR do?
filenameFromUriused the percent-encoded URL segment as the name, so replay encoded names such asphoto%201.pngagain.It now decodes that segment once and takes its basename with
path.win32.basename, which handles both slash styles on every platform.project%2Fcover%20image.pngbecomescover image.png. Zed query paths keep their existing handling, and malformed escapes still fall back to the original segment.How did you verify your code works?
Changed the existing prompt wire test to expect
cover image.png, confirmed it failed before the correction, then passed afterward. All 100 ACP tests andbun run checkpass locally. Separate checks cover encoded slashes and backslashes, replay, Zed paths and malformed escapes.Screenshots / recordings
Not a UI change.
Checklist