Skip to content

[BUG] cmd.run quotation handling with Windows and Powershell #68118

Closed

Description

@Obiron801

Description
Since upgrading to 3006.11, we see quotes being handled improperly when shell=powershell.
Issue is not present in 3006.10

Setup

  • VM
  • classic packaging via EXE installer

Steps to Reproduce the behavior
No shell specified - behaves properly

salt 'minion' cmd.run 'echo "This is a test"'
minion:
    "This is a test"

Powershell specified - carriage returns are introduced

salt 'minion' cmd.run 'echo "This is a test"' shell=powershell
minion:
    This
    is
    a
    test

Powershell specified, quotes escaped - behaves properly

salt 'minion' cmd.run 'echo \"This is a test\"' shell=powershell
minion:
    This is a test

Expected behavior
Nested quotes should be handled properly when shell=powershell, without the need to be escaped.

Versions Report

salt --versions-report
Salt Version:
          Salt: 3006.11

Python Version:
        Python: 3.10.17 (heads/main:5c7faf2, May 11 2025, 04:07:07) [MSC v.1943 64 bit (AMD64)]

Dependency Versions:
          cffi: 1.14.6
      cherrypy: 18.6.1
  cryptography: 42.0.5
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: 4.0.7
     gitpython: Not Installed
        Jinja2: 3.1.6
       libgit2: Not Installed
  looseversion: 1.0.2
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 22.0
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.19.1
        pygit2: Not Installed
  python-gnupg: 0.4.8
        PyYAML: 6.0.1
         PyZMQ: 25.0.2
        relenv: 0.19.2
         smmap: 4.0.0
       timelib: 0.2.4
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist:
        locale: utf-8
       machine: AMD64
       release: 2019Server
        system: Windows
       version: 2019Server 10.0.17763 SP0 Multiprocessor Free

Similar issues
68096

Activity

  1. added
    bug
    on Jun 26, 2025
  2. changed the title [-][BUG] cmd.run quotation handling with Window and Powershell[/-] [+][BUG] cmd.run quotation handling with Windows and Powershell[/+] on Jun 26, 2025
  3. ITJamie commented on Jun 26, 2025

    @ITJamie
    Contributor

    Checkout this other issue. Might be a dup or overlap #68096

  4. Obiron801 commented on Jun 26, 2025

    @Obiron801
    Author

    Checkout this other issue. Might be a dup or overlap #68096

    That's a good call. Case 3 & 4 in that issue are fixed by 68056, which references commands wrapped in parens. There may be some overlap, my example just shows that it also applies to commands wrapped in quotes.

  5. dwoz commented on Jun 26, 2025

    @dwoz
    Contributor

    3006.13 was released today. I think it might resolve this. @twangboy ?

  6. twangboy commented on Jun 27, 2025

    @twangboy
    Contributor

    Please test this on 3006.13. It seems to be working for me.

  7. Obiron801 commented on Jun 27, 2025

    @Obiron801
    Author

    @dwoz @twangboy I still see this issue in 3006.13. I made a mistake in my initial bug report. We installed via msi, not exe, in case that matters. I did test with both msi and exe though and saw the same results.

    I fully uninstalled the Salt Minion and started with a fresh install of 3006.10, then installed 3006.11 and 3006.13 to test, then back to 3006.10.
    The Salt Master stayed at 3006.11 through an initial run of this test. Then I upgraded the master to 3006.13 with no change in behavior.

    salt 'minion' grains.get saltversion
    minion:
        3006.10
    salt 'minion' cmd.run 'echo "This is a test"' shell=powershell
    minion:
        This is a test
    
    salt 'minion' grains.get saltversion
    minion:
        3006.11
    salt 'minion' cmd.run 'echo "This is a test"' shell=powershell
    minion:
        This
        is
        a
        test
    
    salt 'minion' grains.get saltversion
    minion:
        3006.13
    salt 'minion' cmd.run 'echo "This is a test"' shell=powershell
    minion:
        This
        is
        a
        test
    
    salt 'minion' grains.get saltversion
    minion:
        3006.10
    salt 'minion' cmd.run 'echo "This is a test"' shell=powershell
    minion:
        This is a test
    
  8. self-assigned this
    on Jun 27, 2025
  9. added theissue type on Jun 27, 2025
  10. added this to the Sulfur v3006.14 milestone on Jun 27, 2025
  11. Obiron801 commented on Jun 27, 2025

    @Obiron801
    Author

    Adding a little more context from some testing today. While I initially called out quotes as the issue, it seems to be certain separators within the quotes. Spaces in the case I've mentioned, but also commas.

    salt 'minion' grains.get saltversion
    minion:
        3006.13
    salt 'minion' cmd.run 'echo "This,is,a,test"' shell=powershell
    minion:
        This
        is
        a
        test
    

    I noticed this while running another state that sends a comma separated list, and only the first value was being parsed.

    That might make this issue more closely related to 68095

  12. twangboy commented on Jun 30, 2025

    @twangboy
    Contributor

    I'll look at this some more

  13. darkpixel commented on Jul 7, 2025

    @darkpixel
    Contributor

    This also appears to be hitting 3007.5.

  14. linked a pull request that will close this issuecmdmod enhancements for Windows #68156on Jul 9, 2025
  15. darkpixel commented on Jul 24, 2025

    @darkpixel
    Contributor

    Can the fix go into 3007.x too?

    # salt 'MINION*' cmd.run '$p = Get-Printer "Main-Copier"; if ($p -and $p.DriverName -eq "HP Universal Printing PCL 6") { exit 0 } else { exit 1 }' shell=powershell
    MINION:
        At line:1 char:68
        + ... et-Printer Main-Copier; if ($p -and $p.DriverName -eq HP Univ ...
        +                                                                  ~
        You must provide a value expression following the '-eq' operator.
        At line:1 char:69
        + ... Printer Main-Copier; if ($p -and $p.DriverName -eq HP Univers ...
        +                                                                ~~
        Unexpected token 'HP' in expression or statement.
        At line:1 char:69
        + ... Printer Main-Copier; if ($p -and $p.DriverName -eq HP Univers ...
        +                                                                ~~
        Missing closing ')' after expression in 'if' statement.
        At line:1 char:96
        + ... r; if ($p -and $p.DriverName -eq HP Universal Printing PCL 6) { exit  ...
        +                                                                 ~
        Unexpected token ')' in expression or statement.
        At line:1 char:109
        + ... p.DriverName -eq HP Universal Printing PCL 6) { exit 0 } else { exit  ...
        +                                                              ~~~~
        Unexpected token 'else' in expression or statement.
            + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
            + FullyQualifiedErrorId : ExpectedValueExpression
    
    
    -------------------------------------------
    Summary
    -------------------------------------------
    # of minions targeted: 1
    # of minions returned: 1
    # of minions that did not return: 0
    # of minions with errors: 1
    -------------------------------------------
    ERROR: Minions returned with non-zero exit code
    
    # salt 'MINION*' cmd.run "$p = Get-Printer 'Main-Copier'; if ($p -and $p.DriverName -eq 'HP Universal Printing PCL 6') { exit 0 } else { exit 1 }" shell=powershell
    MINION:
        & : The term '=' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the 
        spelling of the name, or if a path was included, verify that the path is correct and try again.
        At line:1 char:3
        + & = Get-Printer 'Main-Copier'; if ( -and .DriverName -eq 'HP Universa ...
        +   ~
            + CategoryInfo          : ObjectNotFound: (=:String) [], CommandNotFoundException
            + FullyQualifiedErrorId : CommandNotFoundException
         
        -and : The term '-and' is not recognized as the name of a cmdlet, function, script file, or operable program. Check 
        the spelling of the name, or if a path was included, verify that the path is correct and try again.
        At line:1 char:37
        + & = Get-Printer 'Main-Copier'; if ( -and .DriverName -eq 'HP Universa ...
        +                                     ~~~~
            + CategoryInfo          : ObjectNotFound: (-and:String) [], CommandNotFoundException
            + FullyQualifiedErrorId : CommandNotFoundException
    
    
    -------------------------------------------
    Summary
    -------------------------------------------
    # of minions targeted: 1
    # of minions returned: 1
    # of minions that did not return: 0
    # of minions with errors: 1
    -------------------------------------------
    ERROR: Minions returned with non-zero exit code
    
    # salt 'MINION*' test.version
    MINION:
        3007.6
    
    
    -------------------------------------------
    Summary
    -------------------------------------------
    # of minions targeted: 1
    # of minions returned: 1
    # of minions that did not return: 0
    # of minions with errors: 0
    -------------------------------------------
    # 
    
  16. twangboy commented on Jul 31, 2025

    @twangboy
    Contributor

    We merge fixes from the 3006.x branch to all later branches. #68156 should merge forward into higher branches.

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

Metadata

Metadata

Assignees

Labels

bugneeds-triage

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions