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

WSL paths need further escape of single quotes #18006

Closed
a4lg opened this issue Oct 8, 2024 · 0 comments · Fixed by #18007
Closed

WSL paths need further escape of single quotes #18006

a4lg opened this issue Oct 8, 2024 · 0 comments · Fixed by #18007
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) In-PR This issue has a related PR Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Tag-Fix Doesn't match tag requirements Product-Terminal The new Windows Terminal.

Comments

@a4lg
Copy link
Contributor

a4lg commented Oct 8, 2024

Windows Terminal version

1.20.11781.0

Windows build number

10.0.26100.0

Other Software

Ubuntu 24.04 (in WSL and source of Windows.Terminal.Wsl in the profile; any WSL distributions are affected)

Steps to reproduce

  1. Open a WSL tab.
  2. Drag and drop a file/folder (the full path needs at least one single quote ' character), say D:\John's Archive.

Expected Behavior

When

D:\John's Archive

is dropped to a WSL tab, a string which expands to:

/mnt/d/John's Archive

(single argument) in the shell should be dropped.

An example satisfying this condition includes '/mnt/d/John'"'"'s Archive' (escaping a single quote ' with '"'"' (finish quote, print a single quote character then begin quote again).

Note: the expected behavior may differ depending on which environment we should assume.
This expected behavior here is of the POSIX shell context and I think this is reasonable.

Actual Behavior

In the dropped path, single quotes in the original full path are kept as-is (D:\John's Archive'/mnt/d/John's Archive').

This is clearly wrong in the POSIX shell context because a quoted string ends before s and the space after s is not quoted and will not be preserved.

@a4lg a4lg added Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Oct 8, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the In-PR This issue has a related PR label Oct 8, 2024
@carlos-zamora carlos-zamora added Product-Terminal The new Windows Terminal. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Oct 9, 2024
@carlos-zamora carlos-zamora added this to the Terminal v1.23 milestone Oct 9, 2024
@carlos-zamora carlos-zamora added the Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) label Oct 9, 2024
a4lg added a commit to a4lg/terminal that referenced this issue Nov 22, 2024
When file/folder is dropped to the terminal, its path is translated and
quoted with a pair of single quotes if necessary.

However, despite that the Win32 subsystem allows single quote, the
terminal control does not escape it.  It causes a path containing one or
more single quotes incorrect on the POSIX shell context
(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).
a4lg added a commit to a4lg/terminal that referenced this issue Nov 22, 2024
When file/folder is dropped to the terminal, its path is translated and
quoted with a pair of single quotes if necessary.

However, despite that the Win32 subsystem allows single quote, the
terminal control does not escape it.  It causes a path containing one or
more single quotes incorrect on the POSIX shell context
(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).
a4lg added a commit to a4lg/terminal that referenced this issue Nov 22, 2024
When file/folder is dropped to the terminal, its path is translated and
quoted with a pair of single quotes if necessary.

However, despite that the Win32 subsystem allows single quote, the
terminal control does not escape it.  It causes a path containing one or
more single quotes incorrect on the POSIX shell context
(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).
a4lg added a commit to a4lg/terminal that referenced this issue Nov 23, 2024
When file/folder is dropped to the terminal, its path is translated and
quoted with a pair of single quotes if necessary.

However, despite that the Win32 subsystem allows single quote, the
terminal control does not escape it.  It causes a path containing one or
more single quotes incorrect on the POSIX shell context
(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.
a4lg added a commit to a4lg/terminal that referenced this issue Nov 23, 2024
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.
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Tag-Fix Doesn't match tag requirements label Nov 23, 2024
a4lg added a commit to a4lg/terminal that referenced this issue Nov 24, 2024
When file/folder is dropped to the terminal, its path is translated and
quoted with a pair of single quotes if the profile is of the WSL.

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

On WSL profiles, 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 WSL path translation is required.
DHowett pushed a commit that referenced this issue Nov 25, 2024
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.

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

* 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.

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

* #18006
* #16214
* #18195

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

Closes #18006

(cherry picked from commit ae90d52)
Service-Card-Id: PVTI_lADOAF3p4s4AmhmszgVEvdY
Service-Version: 1.21
DHowett pushed a commit that referenced this issue Nov 25, 2024
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.

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

* 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.

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

* #18006
* #16214
* #18195

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

Closes #18006

(cherry picked from commit ae90d52)
Service-Card-Id: PVTI_lADOAF3p4s4AmhmQzgVEvdU
Service-Version: 1.22
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.) In-PR This issue has a related PR Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Tag-Fix Doesn't match tag requirements Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants