Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape single quotes while translating dropped Win32 paths #18007

Merged
merged 1 commit into from
Nov 23, 2024

Conversation

a4lg
Copy link
Contributor

@a4lg a4lg commented Oct 8, 2024

Summary of the Pull Request

When file/folder is dropped to the terminal, its path is translated and quoted with a pair of single quotes if necessary.

However, the terminal control does not escape single quotes (allowed in the Win32 subsystem) that need escapes when translated.

On the translation styles other than "none" (note: all other translation styles are currently intended for the POSIX shell), it causes incorrect path to be pasted when the path contains one or more single quotes (see #18006 for an example).

With this commit, the terminal control escapes a single quote with a valid escape sequence '\'' (finish quote, print a single quote then begin quote again) when the path translation is required.

History

v1 → v2

  • Changed escape sequence from '"'"' to much shorter '\''.
  • Reflected comments by the reviewer.

v2 → v3

  • Overhaul after addition of multiple path translation styles (not just WSL but Cygwin and MSYS).
  • More clarification both in the code and in the commit message.

v3 → v4 (current)

  • Minor clarification both in the code and in the commit message.

References and Relevant Issues

Detailed Description of the Pull Request / Additional comments

This is a follow-up of #16214 and #18195, fixing #18006.

Validation Steps Performed

PR Checklist

@microsoft-github-policy-service microsoft-github-policy-service bot added the Issue-Bug It either shouldn't be doing this or needs an investigation. label Oct 8, 2024
@a4lg
Copy link
Contributor Author

a4lg commented Oct 8, 2024

@microsoft-github-policy-service agree

@lhecker
Copy link
Member

lhecker commented Oct 8, 2024

Would it be simpler to paste with double quotes and handle escaping of significant characters like $, ', or " with backspaces?

@a4lg
Copy link
Contributor Author

a4lg commented Oct 8, 2024

@lhecker I would prefer searching for just one character ('), not three (three you mentioned minus ' plus backquote) I guess. Plus, single quote approach makes making mistakes or shell-dependent sequences almost impossible.

The inserting sequence '"'"' is odd (I have to admit) but in both quote cases (double and single), we would not escape so frequently.

@a4lg
Copy link
Contributor Author

a4lg commented Oct 8, 2024

Also, escaping just like @sh formatting logic in jq seems simpler. Will change:

Old: '"'"'
New: '\''

Additional references:

  1. POSIX Shell & Utilities: 2.2 Quoting
  2. POSIX Shell & Utilities: 2.2.1 Escape Character (Backslash)
  3. jq 1.7 Manual: Format strings and escaping (Examples)

@DHowett
Copy link
Member

DHowett commented Nov 18, 2024

Hey, sorry about this - I didn't realize we had an open PR in this area when I changed how path translation works. You will probably have conflicts or outright failures once you merge main because isWSL has moved to a farm upstate.

@a4lg
Copy link
Contributor Author

a4lg commented Nov 22, 2024

@DHowett I see. I'll check the code again and resubmit the new version later (if #18006 is remaining).

@a4lg
Copy link
Contributor Author

a4lg commented Nov 22, 2024

Checked.
Surprisingly, there's no merge conflicts... but fails to compile due to the lost isWSL variable.

The solution seems to be simple and working on it.

@a4lg a4lg changed the title Escape single quotes for WSL Escape single quotes while translating dropped Win32 paths Nov 22, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Product-Terminal The new Windows Terminal. labels Nov 22, 2024

This comment has been minimized.

@a4lg
Copy link
Contributor Author

a4lg commented Nov 22, 2024

Overhauled the PR to adopt my changes over @DHowett's.

@a4lg a4lg force-pushed the wsl-escape-single-quotes branch 2 times, most recently from d7b92af to e942600 Compare November 23, 2024 01:01
When file/folder is dropped to the terminal, its path is translated and
quoted with a pair of single quotes if necessary.

However, the terminal control does not escape single quotes (allowed in
the Win32 subsystem) that need escapes when translated.

On the translation styles other than "none" (note: all other translation
styles are currently intended for the POSIX shell), it causes incorrect
path to be pasted when the path contains one or more single quotes
(see Issue microsoft#18006 for an example).

With this commit, the terminal control escapes a single quote with a
valid escape sequence `'\''` (finish quote, print a single quote then
begin quote again) when the path translation is required.
Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

Thank you so much for this fix, and for your apparently infinite patience. I, and the team, really appreciate it!

@DHowett DHowett merged commit ae90d52 into microsoft:main Nov 23, 2024
15 checks passed
@a4lg
Copy link
Contributor Author

a4lg commented Nov 24, 2024

@DHowett @lhecker
I'm glad to see that there's a plan to fix #18006 for version 1.21 and 1.22 (on the servicing pipeline)!
For the time your team incorporate (backport) the fix in those versions, I made a branch wsl-escape-single-quotes-for-v1.22.

The code is identical to the PR version 2 (that fits 1.21 and 1.22 better than version 4) but incorporates some clarifications from the final merged version (PR version 4).

@DHowett
Copy link
Member

DHowett commented Nov 24, 2024

Sweet! That saves me a bunch of time as usually I’m doing the backports myself. Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal.
Projects
Status: To Cherry Pick
Status: To Cherry Pick
Development

Successfully merging this pull request may close these issues.

WSL paths need further escape of single quotes
3 participants