GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Enable path globbing for native commands by andyleejordan · Pull Request #1639 · PowerShell/PowerShell

Conversation

@andyleejordan

@andyleejordan Andy Jordan (andyleejordan) commented Aug 4, 2016

Copy link
Copy Markdown
Member
  • Resolves issue Implement shell globbing #954.
  • Code is rebased on origin/master.
  • Add tests that fail without your changes. Pending
  • Update all relevant documentation. Pending

Enable path globbing for native commands

E.g. ls *.md expands to ls /path/to/README.md /path/to/CHANGELOG.md

If expansion fails, the argument is sent literally, so ls foo* results in /usr/bin/ls: cannot access foo*: No such file or directory.

Don't glob expand if the verbatim marker was used.

/cc Jason Shirk (@lzybkr) James Truher (@JamesWTruher)

After tracing what the native command parameter binder does, it seems most reasonable to add this logic to appendOneNativeArgument. I know that doesn't sound right, but in fact it already deals with being sent an argument that gets expanded to a list. However I could be completely wrong, as the code around here is a bit strange.

When a parameter.ParameterNameSpecified is true, we don't want to glob, as this correlates to -flag. Moreover, the CommandParameterInternal should probably be updated to interpret --flag as a Parameter (instead of an Argument); as it does not currently.

We want to glob when parameter.ArgumentSpecified is true, and only once it's been converted to a string (or expanded to a set of strings) (which happens in the poorly named appendOneNativeArgument function).

We do not want to glob if the --% verbatim marker was seen.

I need to add tests, but figured I'd get this up for review.

Also I already have one known bug: globbing doesn't appear to work for .dotfiles. So although *.md works, .gi* and *git* does not work. But it doesn't have anything to do with these changes, it fails similarly for Get-ChildItem too. I'll file a bug report tomorrow.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@andyleejordan
Enable path globbing for native commands
8774be3
E.g. `ls *.md` expands to `ls /path/to/README.md /path/to/CHANGELOG.md`

If expansion fails, the argument is sent literally, so `ls foo*` results
in `/usr/bin/ls: cannot access foo*: No such file or directory`.

Don't glob expand if the verbatim marker was used.
@andyleejordan Andy Jordan (andyleejordan) added the Review - needed label Aug 4, 2016
andyleejordan
andyleejordan reviewed Aug 4, 2016
View reviewed changes
Comment thread src/System.Management.Automation/engine/NativeCommandParameterBinder.cs

foreach (string path in resolvedPaths)
{
arg = path;

@andyleejordan Andy Jordan (andyleejordan) Aug 4, 2016

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

There are cases in the following loop where arg gets modified, so path cannot be used as it's an iterator. So arg = path seemed to be the cleanest solution (and meant not having to rename the variable elsewhere).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@andyleejordan

Andy Jordan (andyleejordan) commented Aug 4, 2016

Copy link
Copy Markdown
Member Author

The globber doesn't appear to be handling escapes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lzybkr

Jason Shirk (lzybkr) commented Aug 5, 2016

Copy link
Copy Markdown
Contributor

The failures are legit - in some cases we can't glob.

At a minimum, I think we can't do globbing on Windows at all - Windows tools implement globbing themselves, so even if we did something, it might work differently than the tool we're calling.

That said, we still need to be smarter somehow as the test failure demonstrates (basically powershell -command "[Console]::WriteLine(1)". I think we're treating the left of :: as a provider (like filesystem) and don't recognize it as a provider.

At a minimum, I think we need a way to escape globbing characters, but that's messy. --% helps here, the test failure wouldn't be a problem in this implementation if it used --%, but that's half the solution because you may want to mix arguments with globbing and no globbing, hence the need for some escape.

The question is - where do process escapes? If it was just in the native command processor, it's less risky, but also less useful. If we do it in the globbing code, we also run a greater risk of breaking something.

I'm fine with punting the escape character for now, make that an issue, but put the globbing under #if UNIX and fix the test to use --%.

andyleejordan reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TravisEz13 Travis Plunk (TravisEz13) added WG-Engine core PowerShell engine, interpreter, and runtime Review - waiting on author and removed Review - needed labels Aug 6, 2016
@TravisEz13

Travis Plunk (TravisEz13) commented Aug 6, 2016

Copy link
Copy Markdown
Member

Removed review needed since tests are failing...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andyleejordan

Andy Jordan (andyleejordan) commented Aug 6, 2016

Copy link
Copy Markdown
Member Author

Closing until I get back to this. Thanks for the review!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andyleejordan Andy Jordan (andyleejordan) closed this Aug 6, 2016
@andyleejordan
Andy Jordan (andyleejordan) deleted the andschwa/globbing branch August 11, 2016 01:24
@andyleejordan Andy Jordan (andyleejordan) mentioned this pull request Aug 31, 2016
Arguments for external executables aren't correctly escaped #1995
Closed
@andyleejordan Andy Jordan (andyleejordan) mentioned this pull request Sep 20, 2016
Enable path globbing for native commands #2325
Closed
4 of 7 tasks
@TravisEz13 Travis Plunk (TravisEz13) added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Review - Waiting on Author labels May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept WG-Engine core PowerShell engine, interpreter, and runtime

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@andyleejordan @lzybkr @TravisEz13
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.