Skip to content

Unexpected escaping of quotes when expanding variable to external command #6465

@MichelMunoz

Description

@MichelMunoz

Describe the bug

Edit:
See the comment further down #6465 (comment) for the issue with current version and quote / paths vs nu command.


Old description:
Despite #2095, in some cases quotes are still removed, thus breaking external commands using them for paths for example.

How to reproduce

If you execute this :

let exe = "^echo"
let somepath = "C:\\Program Files (x86)\\Realtek"
let command = $"($exe) --arg1 \"($somepath)\" -z@\"($somepath)\""
echo $"COMMMAND: ($command)"
nu -c $command

you obtain this :

COMMMAND: ^echo --arg1 "C:\Program Files (x86)\Realtek" -z@"C:\Program Files (x86)\Realtek"
Error: nu::parser::unclosed_delimiter (link)

  × Unclosed delimiter.
   ╭─[source:1:1]
 1 │ ^echo --arg1 C:\Program Files (x86)\Realtek" -z@"C:\Program Files (x86)\Realtek
   ·                                                            ▲
   ·                                                            ╰── unclosed )
   ╰────

after arg1 one double-quote for the path is removed, and after -z one double-quote is removed, for some reason.

Note : The "why" the command is in a variable ($exe) is because the command is known at runtime (depending on OS)

Expected behavior

per #2095 none of the paths double quote should be removed.
The command that should be execute would be what the echo $"COMMMAND: ($command)" shows

Screenshots

N/A

Configuration

nu version 0.66.2
tested on windows

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:external-commandsIssues related to external commandsA:quoting-expansionIssues related to string quoting, interpolation, and expansion of variable or glob patternscategory:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions