Skip to content

fix(opencode): handle shell-escaped parentheses in drag-drop file paths#17082

Open
vdmkotai wants to merge 1 commit intoanomalyco:devfrom
vdmkotai:fix/drag-drop-parens
Open

fix(opencode): handle shell-escaped parentheses in drag-drop file paths#17082
vdmkotai wants to merge 1 commit intoanomalyco:devfrom
vdmkotai:fix/drag-drop-parens

Conversation

@vdmkotai
Copy link

@vdmkotai vdmkotai commented Mar 11, 2026

Issue for this PR

Closes #17075

Type of change

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

What does this PR do?

When you drag-drop a file like image (1).png into Ghostty, the terminal shell-escapes the path: image\ \(1\).png. The TUI paste handler only unescaped \ (backslash-space) but not \( or \), so Filesystem.readArrayBuffer received the wrong path, failed silently, and the paste was swallowed.

Changed the regex from /\\ /g to /\\([^a-zA-Z0-9])/g — this unescapes all shell metacharacters while keeping Windows path separators intact (backslash followed by alphanumeric is never a shell escape).

How did you verify your code works?

Wrote a test script covering 17 cases: the bug scenario (shell-escaped parens/brackets), single-quoted paths, Windows paths (C:\Users\...), plain paths, edge cases (trailing backslash, double backslash, backslash-digit). All 17 pass — bug is fixed and Windows paths are preserved.

Screenshots / recordings

N/A — TUI-only change, no UI modification.

Checklist

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

Terminals like Ghostty shell-escape special characters when drag-dropping
files. The paste handler only unescaped backslash-space but not other
metacharacters like parentheses, causing silent attachment failure for
filenames like 'image (1).png'.

Use /\\([^a-zA-Z0-9])/g to unescape all shell metacharacters while
preserving Windows path separators (backslash + alphanumeric).

Fixes anomalyco#17075
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Mar 11, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Drag-and-drop image attachment fails when filename contains parentheses

1 participant