Skip to content

Parameter parsing/passing: an unquoted argument that starts with a "-" (hyphen) is broken in two at the first "." (period) #6291

Open

Description

Related: #6292 and #6360

Note that . should receive no special treatment in tokens such as -foo=bar.baz, because the token is unquoted and does not start with a special char. ($ @ ( ' " ) and should therefore result in interpretation as an (expandable) string, according to about_Parsing.

In reality, though, the unexpected special treatment stems from - being the 1st character, which causes interpretation as a parameter name, even though that doesn't apply in this case.

Steps to reproduce

# Helper function that echoes all arguments.
function Out-Argument { $i = 0; $Args | % { 'arg[{0}]: {1}' -f $i++, $_ } }

# Pass an unquoted argument that starts with "-" and has an embedded "." (outside of "..." or '...')
Out-Argument -foo=bar.baz

Expected behavior

arg[0]: -foo=bar.baz

Actual behavior

arg[0]: -foo=bar
arg[1]: .baz

The token was unexpectedly broken in two. Note that this equally applies when calling external utilities.

And it is indeed in the context of calling external programs that an argument with such (non-PowerShell) syntax (-<param-name>=<value>) may need to be passed - see this SO question and this one.

(PSv2 exhibited a variation of the bug - see this SO question.)

Environment data

PowerShell Core v6.0.1 on macOS 10.13.3
PowerShell Core v6.0.1 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.1 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.674 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)

Workarounds

# "`"-escape the leading "-"
Out-Argument `-foo=bar.baz

# Quote the whole argument
Out-Argument '-foo=bar.baz'

Activity

  1. added
    WG-Enginecore PowerShell engine, interpreter, and runtime
    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif
    on Mar 2, 2018
  2. SteveL-MSFT commented on Dec 10, 2020

    @SteveL-MSFT
    Member

    Garrett hit this trying to use cmake with pwsh: https://twitter.com/fearthecowboy/status/1336758436583809026

    Twitter
    “I just wandered across the absolute weirdest bug in powershell & pwsh

    When using a parameter that starts with a dash, powershell will insert a space before a period in the command line:

    This is bad when trying to execute a program (example here with cmd /c echo)

    @Steve_MSFT”

  3. mklement0 commented on Dec 10, 2020

    @mklement0
    ContributorAuthor

    Just to clarify, Steve Lee (@SteveL-MSFT): it isn't that a space is inserted - that's just how it manifests in a test command such as cmd /c echo -foo=bar.none; what happens is that the part of the argument starting with the (first) . is passed as a separate argument.

    #14364 should be closed as a duplicate.

  4. SteveL-MSFT commented on Dec 16, 2020

    @SteveL-MSFT
    Member

    @PowerShell/powershell-committee reviewed this, we believe the treatment of the period as an argument separator is a bug that should be fixed. A bucket 3 breaking change.

  5. mklement0 commented on Dec 16, 2020

    @mklement0
    ContributorAuthor

    Glad to hear it, Steve Lee (@SteveL-MSFT).

    I hope that fixing this will also address #6292 and #6360.

  6. added
    Committee-ReviewedPS-Committee has reviewed this and made a decision
    and removed
    Review - CommitteeThe PR/Issue needs a review from the PowerShell Committee
    on Jan 6, 2021
  7. ceztko commented on Oct 6, 2021

    @ceztko

    Is this still on track for 7.2?

  8. 14 remaining items

  9. nathankrueger commented on Feb 8, 2024

    @nathankrueger

    I can't use Powershell for my project because of this.

  10. robbycbennett commented on Feb 16, 2024

    @robbycbennett

    Here's a real example for usage of the period in arguments. File names usually have periods.

    clang++ -std=c++20 use.cpp -fmodule-file=Hello=Hello.pcm Hello.pcm -o Hello.out

    The command was taken from https://clang.llvm.org/docs/StandardCPlusPlusModules.html.

  11. robbycbennett commented on Feb 16, 2024

    @robbycbennett

    This has been an issue for a long time. I see it on version 5 and on version 7.

  12. robbycbennett commented on Feb 17, 2024

    @robbycbennett

    I can see five characters that are allowed in Unix shell unquoted strings that aren't allowed in PowerShell:

    • {
    • }
    • ,
    • .
    • [

    In the file src/System.Management.Automation/engine/parser/tokenizer.cs, if I remove case '.': from line 3211, then this problem is fixed. However, it probably breaks some other functionality.

    Before change:

    PS C:\> echo -Hello.world
    -Hello
    .world

    After change:

    PS C:\> echo -Hello.world    
    -Hello.world
  13. rkeithhill commented on Aug 25, 2025

    @rkeithhill
    Collaborator

    WG-Engine looked at this today and agree it is worth pursuing a bug fix for native commands. Attempting to fix this for commands in general, would be too risky. This area of the code is tricky because the native command parser only gets the tokens that made up the command line, but we believe the original argument can be recreated from these tokens.

  14. added
    Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributors
    WG-ReviewedA Working Group has reviewed this and made a recommendation
    and removed
    WG-NeedsReviewNeeds a review by the labeled Working Group
    on Aug 25, 2025
  15. added a commit that references this issue on Nov 24, 2025
    b179b78
  16. added a commit that references this issue on Nov 24, 2025
    6423fe1
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

    Committee-ReviewedPS-Committee has reviewed this and made a decisionIn-PRIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the productKeepOpenThe bot will ignore these and not auto-closeUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Enginecore PowerShell engine, interpreter, and runtimeWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions