Skip to content

Tokenizer treats . as a separator when parsing a parameter token, which causes problem to argument parsing for native commands #15541

Closed

Description

@delanym

I use powershell to run build commands like
mvn --% install -Dmaven.test.skip -Dmaven.repo.local=.m2/repository -Dbuild.deployAtEnd=true -Dgib.disable

I NEVER expect the dot to act like a property selection operator. I don't want to have to quote every time I use a dot, and I'd rather not have to specify --% for every command.

Is it reasonable to expect a setting in pwsh.runtimeconfig.json to disable parsing of command arguments? Call it dumb mode or whatever.

I see other people are also doing strange things to work around this https://stackoverflow.com/questions/18923315/using-in-powershell

Activity

  1. added
    Issue-Enhancementthe issue is more of a feature request than a bug
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on Jun 8, 2021
  2. vexx32 commented on Jun 8, 2021

    @vexx32
    Collaborator

    Unless I'm missing something, you shouldn't need to use --% most of the time. That command you have there will work as-is without it, I'd think.

  3. delanym commented on Jun 8, 2021

    @delanym
    Author

    You're not the first person to suggest that, but the fact is I've never seen it work without --%, on many machines running powershell 5 or 7. There's even a difference in the syntax highlighting

    image

    What makes you think I don't need the --% ?

  4. rkeithhill commented on Jun 8, 2021

    @rkeithhill
    Collaborator

    Yeah, there is a difference without --%:

    image

    Using --% in PS:

    image

    BTW there is some work going on WRT argument parsing in 7.2 - see PR #15408. However whether the mode is set to Standard or Legacy, PS still parses that mvn command line differently than cmd.exe does.

  5. vexx32 commented on Jun 8, 2021

    @vexx32
    Collaborator

    That feels like a bug, tbh. I don't see any good reason for the . characters to have special meaning. There aren't any variables or other special tokens involved here.

  6. added
    Issue-BugIssue has been identified as a bug in the product
    and removed
    Issue-Enhancementthe issue is more of a feature request than a bug
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on Jun 9, 2021
  7. changed the title [-]Feature Request: dumb mode, i.e. a no parse arguments setting[/-] [+]Tokenizer treats `.` as a separator when parsing a parameter token, which causes problem to argument parsing for native commands[/+] on Jun 9, 2021
  8. daxian-dbw commented on Jun 9, 2021

    @daxian-dbw
    Member

    It looks . is used as a separator when tokenizing text like a parameter (e.g. -xxx)

    PS:24> function bar { param($param) $param }
    PS:25> bar -param.abcdef
    .abcdef
    

    Another native command argument parsing issue related to tokenizer: #15279

  9. ceztko commented on May 6, 2022

    @ceztko

    This seems the same as the older #6291. I fail to understand if this a confirmed bug and if this will be solved in a future version of powershell.

  10. mklement0 commented on Sep 8, 2022

    @mklement0
    Contributor

    Good point, Francesco Pretto (@ceztko). In fact,

    is just one of several related bugs, which the following search surfaces ("Parameter parsing.passing" in the title, 8 issues as of this writing):

    GitHub
    PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.
  11. rkeithhill commented on Nov 28, 2022

    @rkeithhill
    Collaborator

    I ran into this again on macOS with the updated native command passing:

    g++ ./hello.cpp -target arm64-apple-macos11 -mmacosx-version-min=11.0 -o hello_arm  
    clang: error: no such file or directory: '.0'
    

    You can quote the 11.0 to get around this or use --%. The issue seems to be that -mmacosx-version-min=11 is considered a parameter name by PowerShell, followed by a .0 as a ConstantExpressionAst. Possible fix is to recognize this situation in the NativeCommandProcessor and fix up the resulting parameter passed to the native app.

  12. mklement0 commented on Nov 28, 2022

    @mklement0
    Contributor

    Keith Hill (@rkeithhill), it's the same old bug, #6291, and it is both unrelated to and long predates $PSNativeCommandArgumentPassing, as are the other linked bugs.

    The simplest workaround is to quote the whole argument: '-mmacosx-version-min=11.0'
    If the token contains no spaces or other PowerShell metacharacters, `-escaping the initial - is enough:
    `-mmacosx-version-min=11.0

  13. garretwilson commented on Mar 16, 2023

    @garretwilson

    Another one of those, "why? why" issues with PowerShell.

    It's great that PowerShell has extra features and some simplifications. But why should it complicate standard commands? Like why should we change the way we invoke Java since 1997 just because we start using PowerShell? (I can't guarantee that Java has supported -D since 1997, but it's been around quite a while.)

  14. delanym commented on Sep 7, 2023

    @delanym
    Author

    Also, I can't use --% in commands which invoke a script. For example with this script "fast.ps1"

    ./mvnw clean install $args -D"surefire.skip"

    And this command fast --% something

    The token "--%" gets passed to Maven. So I'm forced to quote.

  15. doggy8088 commented on Mar 6, 2024

    @doggy8088

    Delany (@delanym) What's your $PSNativeCommandArgumentPassing value?

  16. delanym commented on Mar 6, 2024

    @delanym
    Author

    Will 保哥 (@doggy8088) i just installed Powershell 7.4.1 and the value is "Windows"

  17. delanym commented on Mar 6, 2024

    @delanym
    Author

    https://learn.microsoft.com/en-us/powershell/scripting/learn/experimental-features?view=powershell-7.4#psnativecommandargumentpassing

    It makes no difference whether this property is set to Windows, Standard or Legacy.

    Lists the currently available experimental features and how to use them.
  18. ceztko commented on Sep 10, 2024

    @ceztko

    Maybe this issue should be kept open/assigned a milestone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions