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

Experimental feature PSNativeWindowsTildeExpansion does not expand when there is backtick escaping #21276

Open
5 tasks done
DHowett opened this issue Feb 27, 2024 · 4 comments · May be fixed by #21277
Open
5 tasks done
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.

Comments

@DHowett
Copy link

DHowett commented Feb 27, 2024

Prerequisites

Steps to reproduce

Enable the PSNativeWindowsTildeExpansion experimental feature.

cmd /c echo ~
cmd /c echo ~/foo
cmd /c echo ~/foo` bar
cmd /c echo "~/foo bar"

Expected behavior

C:\Users\duhowett
C:\Users\duhowett/foo
C:\Users\duhowett/foo bar
"~/foo bar"

Actual behavior

C:\Users\duhowett
C:\Users\duhowett/foo
"~/foo bar"
"~/foo bar"

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.0-preview.2
PSEdition                      Core
GitCommitId                    7.5.0-preview.2
OS                             Microsoft Windows 10.0.23620
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

@DHowett DHowett added the Needs-Triage The issue is new and needs to be triaged by a work group. label Feb 27, 2024
@mklement0
Copy link
Contributor

mklement0 commented Feb 27, 2024

Related (the same bug has existed for a long time on Unix-like platforms, where tilde expansion is a stable feature):

cmd /c echo ~\'foo bar'  # should expand, doesn't
cmd /c echo `~         # shouldn't expand, does
cmd /c echo ~'\'  # shouldn't expand, does

And, with respect to tab-completion:

@SteveL-MSFT
Copy link
Member

SteveL-MSFT commented Mar 4, 2024

@mklement0 I checked my PR branch and your first case works as you expect. For the second case, I don't know if you should expect it not to expand. Even thought you are escaping it, I don't recall another case where it would be treated as a literal. You'd have to enclose it with single-quotes to indicate it's literal. The 3rd case I also don't see any inconsistency in expanding as it resolves to ~\ as the single quotes are not around the tilde.

@mklement0
Copy link
Contributor

mklement0 commented Mar 5, 2024

I checked my PR branch and your first case works as you expect.

Glad to hear it (in my initial response I missed that you were referring to your PR).

For the second case, I don't know if you should expect it not to expand.

By way of analogy: both cmd /c echo `@ and cmd /c echo '@' work to to ensure literal treatment of metacharacter @, so the same should apply here.

The 3rd case I also don't see any inconsistency in expanding as it resolves to ~\ as the single quotes are not around the tilde.

The very purpose of this feature - at least originally - was emulation of the behavior of POSIX-like shells.
You'll find that executing the following from a POSIX-like shell does not result in expansion, and I see no reason to treat the Windows case differently:

# From a POSIX-compatible shell; contrast with: echo ~/ or echo ~/'foo'
# -> '~/'
echo ~'/'

@mklement0
Copy link
Contributor

@SteveL-MSFT, speaking of the analogous case; please see:

I haven't looked into any technical challenges that may prevent interpreting ` as suggested (you'll need to know early in the parameter-binding process whether a given char. was `-prefixed), but it certainly makes sense to exhibit the suggested behaviors from a user's perspective.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants