Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerShell on Windows tab completed paths lead to inconsistent parsing #416

Open
agc93 opened this issue May 16, 2021 · 3 comments
Open
Labels
bug Something isn't working

Comments

@agc93
Copy link

agc93 commented May 16, 2021

Information

  • OS: Windows (only)
  • Version: 0.39.0
  • Terminal: Windows Terminal and default console tested.

Describe the bug

This isn't strictly a bug but I'm hoping there's something I can do to minimize user friction here.

If a user tab-completes a path in PowerShell on Windows that includes a space, the resulting path gets parsed sort-of-incorrectly resulting in arguments being merged together and generally strange quoting behaviour. This all comes from the fact that PowerShell's behaviour is to use quotes with a backslash as path separator and includes a trailing slash, essentially escaping the end of the path.

To Reproduce

I've created a simple-ish repro with samples at this repo that should explain things a little more clearly.

Expected behavior
I understand that this isn't really Spectre.Console's problem and is really just crappy behaviour from PowerShell but if there was a way to flag an argument as being a path so that it was parsed differently that might be useful? or avoiding this behaviour is already possible and I'm an idiot 😆

Screenshots

image

Additional context
This is unique to PowerShell on Windows since cmd doesn't default to including the trailing slash, and pwsh on other platforms uses their much saner path separator.


Please upvote 👍 this issue if you are interested in it.

@agc93 agc93 added the bug Something isn't working label May 16, 2021
@phil-scott-78
Copy link
Contributor

Yeah, that behavior of powershell is pretty frustrating. I'm honestly surprised it can't be toggled, at least not anyway that seems obvious to me.

That being said, I don't think we will be able to work around that behavior. It would require a custom command line parser, which is a kind of notoriously complex thing to do. Having a custom CommandLineToArgvW for this scenario would almost certainly break others as we play whack a mole trying to match the normal behavior with our custom one.

I vote creating an issue with the powershell team. This is more than just a Spectre issue or even .net

@phil-scott-78
Copy link
Contributor

One thing I forgot to add is I've been toying around with the idea of adding auto completion to CLI app and there might be an opportunity to override this behavior. Issue #267 tracks this. No progress yet, but I'll definitely keep this scenario in mind

@phaselden
Copy link

phaselden commented Aug 12, 2021

Am not 100% sure this is the same underlying issue but...

I have a app which I call like this:
MyApp.exe process "C:\TestData\EDB\"

The quotes are added to the last arg in case the directory path includes a space.

If the path includes the trailing backslash like shown above, then the property value that ends up in the (Command)Settings is:
C:\TestData\EDB"
That is, there is a double-quote char on the end. It looks like something has interpretted the trailing slash as an escape char.

If the trailing backslash is not included, the Settings value is interpretted correctly:
C:\TestData\EDB

[UPDATE]
Actually.... I had a look at the args array being passed into into Program.Main, and the value in there has the extra trailing double-quote, so it doesn't seem to be a Spectre.Console thing at all.

[UPDATE 2]
Seems it is a known issue. eg. https://docs.microsoft.com/en-us/archive/blogs/twistylittlepassagesallalike/everyone-quotes-command-line-arguments-the-wrong-way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

4 participants