Skip to content

fix(acp): decode URL-encoded attachment filenames - #59793

Closed
andreivince wants to merge 2 commits into
anomalyco:devfrom
andreivince:acp-attachment-filenames
Closed

andreivince wants to merge 2 commits into
anomalyco:devfrom
andreivince:acp-attachment-filenames

Conversation

@andreivince

@andreivince andreivince commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #59792

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

filenameFromUri used the percent-encoded URL segment as the name, so replay encoded names such as photo%201.png again.

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.png becomes cover 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 and bun run check pass locally. Separate checks cover encoded slashes and backslashes, replay, Zed paths and malformed escapes.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copilot AI balanced review requested due to automatic review settings October 28, 2026 01:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works. I ran promptContentToParts and the replay conversion on the base and on this branch:

  • file:///tmp/photo%201.png now gives the name photo 1.png instead of photo%201.png.
  • Replay now produces photo%201.png instead of the double-encoded photo%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).

Comment thread packages/cli/src/acp/content.ts Outdated
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.png and café #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ACP: attachment filenames stay URL-encoded

2 participants