Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/pwsh-install-template.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ function PSConsoleHostReadLine {
$argsStart = $wordEnd
# IndexOfAny beats running the regex per arg.
if ($source.IndexOfAny($script:__COREUTILS_ARG_SPECIAL__) -lt 0) {
# PowerShell's Legacy native argument mode can split extension-like
# 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.
Comment thread
caomengxuan666 marked this conversation as resolved.
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.

This comment was marked as duplicate.

$source.IndexOfAny([char[]]@('*', '?', '[', ']')) -lt 0) {
$rewrittenArgs += "'" + ((__coreutils_q $source).Replace("'", "''")) + "'"
$i++
continue
}
$rewrittenArgs += $source
$i++
continue
Expand Down