Skip to content

Pasted text containing $ gets corrupted when expanding [Pasted ~N lines] placeholders #33699

Description

@itsybitsybootsy

Description

Pasting text into the TUI prompt collapses it into a [Pasted ~N lines] placeholder, with the real text stored on the prompt part. When that placeholder is expanded back to the full text, the pasted text is passed as the replacement string to String.prototype.replace. A string replacement interprets $ sequences ($$, $&, $`, $'), so pasted code that contains them comes back altered.

Two flows are affected: copying the prompt back to the clipboard, and opening the prompt in the external editor. The submit path is fine because it uses the range-based expander.

Examples (pasted text on the left, what you get back on the right):

  • const x = ${a}$$ becomes const x = ${a}$ (the $$ collapses to one $)
  • echo $&done becomes echo [Pasted ~N lines]done ($& re-inserts the placeholder string into the code)
  • $` and $' are mangled the same way (they pull in text from around the placeholder)

OpenCode version

dev (1.17.9)

Steps to reproduce

  1. Paste a multi-line block containing $$ or $& (shell or template-literal code, for example) into the prompt so it collapses to [Pasted ~N lines].
  2. Copy the prompt to the clipboard, or open it in the external editor.
  3. The text you get back differs from what you pasted.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions