PowerShell / PowerShell

PowerShell for every system!
https://microsoft.com/PowerShell
MIT License
43.66k stars 7.08k forks source link

Need syntax or cmdlet for globbing with space (i.e. glue quoted literals with globs) #13098

Closed Artoria2e5 closed 1 week ago

Artoria2e5 commented 3 years ago

I found this issue while trying to take on #13089 myself. It's a minor headache to be unable to glob stuff with escapes and embedded spaces. This is not a limitation in POSIX shell, nor is it one in the original glob(3) language.

Steps to reproduce

# prepare
$a = mktemp -d
cd $a
mkdir "A B"
# test
/bin/echo "A "*
/bin/echo *' B'
/bin/echo *` B
# ast poke sans globbing
Write-Output "A "*
Write-Output *' B'

Expected behavior

A B
A B
A B
(pwsh stuff)
(pwsh stuff)

Actual behavior

A  A B
* B
* B
A 
*
* B

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.2
PSEdition                      Core
GitCommitId                    7.0.2
OS                             Darwin 19.5.0 Darwin Kernel Version 19.5.0: Tue…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

How did this happen?

Test case (4) indicates that the parser sees two string literals glued together as two distinct "words". This could be improved without breakings stuff by just making a cmdlet for globbing a mixture of quoted (to be escaped) and bare (to be put into the pattern raw) character runs.

Test case (3) indicates that the heuristic in NativeCommandParameterBinder::AppendOneNativeArgument is inadequate. Even when fed a valid glob, it sees the space in the string and decides that it is non-globbable from that. Bad idea.

Artoria2e5 commented 6 months ago

Four in a row!

microsoft-github-policy-service[bot] commented 2 weeks ago

This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.

Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.