fix(tui): expand pasted text placeholders literally#33700
Open
itsybitsybootsy wants to merge 1 commit into
Open
fix(tui): expand pasted text placeholders literally#33700itsybitsybootsy wants to merge 1 commit into
itsybitsybootsy wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #33699
Type of change
What does this PR do?
expandPastedTextPlaceholdersre-inflates a[Pasted ~N lines]placeholder withresult.replace(marker, part.text). When the second argument is a string,replacetreats$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.tsfor$$,$&,$`,$', 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 andtsgo --noEmitis clean.Screenshots / recordings
Not a UI change.
Checklist