Skip to content

fix(tui): expand pasted text placeholders literally#33700

Open
itsybitsybootsy wants to merge 1 commit into
anomalyco:devfrom
itsybitsybootsy:fix-paste-expand
Open

fix(tui): expand pasted text placeholders literally#33700
itsybitsybootsy wants to merge 1 commit into
anomalyco:devfrom
itsybitsybootsy:fix-paste-expand

Conversation

@itsybitsybootsy

Copy link
Copy Markdown

Issue for this PR

Closes #33699

Type of change

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

What does this PR do?

expandPastedTextPlaceholders re-inflates a [Pasted ~N lines] placeholder with result.replace(marker, part.text). When the second argument is a string, replace treats $ sequences in it as patterns, so pasted text containing $$, $&, $`, or $' came back changed. $& was the worst case: it re-inserted the placeholder string itself into the user's code.

Passing a function instead (() => part.text) inserts the text verbatim.

The "open editor" command had its own copy of the old loop, so I pointed it at the same helper. The submit path was already safe (it uses the range-based expandTrackedPastedText).

How did you verify your code works?

Added tests in packages/tui/test/prompt/part.test.ts for $$, $&, $`, $', a repeated placeholder, and a non-pasted part. They fail on the old code and pass with the fix. The tui test suite has no new failures and tsgo --noEmit is clean.

Screenshots / recordings

Not a UI change.

Checklist

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

result.replace with a string replacement treated $ sequences in pasted
text ($$, $&, $`, $') as patterns, corrupting pasted code when expanding
[Pasted ~N lines] placeholders for clipboard copy and the editor. Use a
function replacement so the text is inserted verbatim, and route the
editor command through the same helper.
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.

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

1 participant