Quote dash-prefixed path arguments in PowerShell wrapper#25
Quote dash-prefixed path arguments in PowerShell wrapper#25caomengxuan666 wants to merge 1 commit into
Conversation
| # 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
This comment was marked as duplicate.
Sorry, something went wrong.
Fixes one argument-passing edge case from #23.
In the PowerShell wrapper, bare arguments like
-dash.txtare currently passed through unchanged. For.cmdtargets running in Legacy native argument mode, PowerShell can split that token as-dashand.txt.This change quotes extension-like dash-prefixed bare tokens before handing them to the
.cmdentry point, while leaving ordinary bare globs unquoted so coreutils can still expand them.Validated locally with the generated wrapper form:
All three commands succeeded against a file named
-dash.txt.