Skip to content

Quote dash-prefixed path arguments in PowerShell wrapper#25

Open
caomengxuan666 wants to merge 1 commit into
microsoft:mainfrom
caomengxuan666:winuxcmd/quote-dash-paths
Open

Quote dash-prefixed path arguments in PowerShell wrapper#25
caomengxuan666 wants to merge 1 commit into
microsoft:mainfrom
caomengxuan666:winuxcmd/quote-dash-paths

Conversation

@caomengxuan666

Copy link
Copy Markdown
Contributor

Fixes one argument-passing edge case from #23.

In the PowerShell wrapper, bare arguments like -dash.txt are currently passed through unchanged. For .cmd targets running in Legacy native argument mode, PowerShell can split that token as -dash and .txt.

This change quotes extension-like dash-prefixed bare tokens before handing them to the .cmd entry point, while leaving ordinary bare globs unquoted so coreutils can still expand them.

Validated locally with the generated wrapper form:

cat -- '"-dash.txt"'
grep foo -- '"-dash.txt"'
cp -- '"-dash.txt"' dash-copy.txt

All three commands succeeded against a file named -dash.txt.

Comment thread src/pwsh-install-template.ps1
@lhecker lhecker added the C-bug It shouldn't be doing this. label Jun 9, 2026
# parameter tokens (e.g. -dash.txt -> -dash + .txt) for .cmd
# targets. Quote these tokens while leaving ordinary bare globs
# unquoted so coreutils can still expand them.
if ($source -match '^-[^-][^\s]*\.[^\s]*$' -and

@IDisposable IDisposable Jun 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This regex will match -., -a., and -.a, if that isn't desired, should we use:

  • ^-[^-](?!\.$)[^\s]*\.[^\s]*$ which will not match -.
  • ^-[^-][^\s]+\.[^\s]+$ which requires something on both sides -a.b

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This PR is excellent, but I hesitate to merge it for a similar reason: I find it hard to reason about why PowerShell fails this way and how we can fix it in the most robust manner.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This regex will match -., -a., and -.a, if that isn't desired, should we use:

  • ^-[^-](?!\.$)[^\s]*\.[^\s]*$ which will not match -.
  • ^-[^-][^\s]+\.[^\s]+$ which requires something on both sides -a.b

Your concern is right,this regex is too loose.I will improve it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This PR is excellent, but I hesitate to merge it for a similar reason: I find it hard to reason about why PowerShell fails this way and how we can fix it in the most robust manner.

Yeah, we need to find out the reason first. An end-to-end test would help ensure correctness, but I agree that we need a deeper understanding of why PowerShell splits these tokens before we can design a robust fix. I'll investigate further.

# parameter tokens (e.g. -dash.txt -> -dash + .txt) for .cmd
# targets. Quote these tokens while leaving ordinary bare globs
# unquoted so coreutils can still expand them.
if ($source -match '^-[^-][^\s]*\.[^\s]*$' -and

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-bug It shouldn't be doing this.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants