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

Escaped quotes in symbol parameter values lost or cause errors #1704

Closed
patridge opened this issue Nov 14, 2018 · 8 comments
Closed

Escaped quotes in symbol parameter values lost or cause errors #1704

patridge opened this issue Nov 14, 2018 · 8 comments
Assignees
Labels
triaged The issue was evaluated by the triage team, placed on correct area, next action defined.
Milestone

Comments

@patridge
Copy link
Contributor

patridge commented Nov 14, 2018

When I try to pass quotation marks to a parameter from the command line, I either get an error or the produced content will not contain quotation marks.

Full details can be found in my sample repo notes, but here are some examples.

dotnet new repro-quotes-spaces --someparameter="something needing `"escaped quotes`" in it."

Results in this error:

Invalid input switch:
  quotes in it.

If I remove the space within the quoted sub-string, there is no error, but the content it produces doesn't have any quotation marks either.

dotnet new repro-quotes-spaces --someparameter="something needing `"escapedquotes`" (without spaces) in it."

Results in this text missing the expected quotes:

something needing escapedquotes (without spaces) in it.

Environment

  • Windows 10 Pro 1803 and macOS v10.13.6 (High Sierra)
  • .NET Core SDK: v2.1.500 (also tested on v2.1.302)
  • PowerShell Core: v6.1.0

Sample repro

Here is a repo containing a sample and my notes so far (Notes direct link):

https://github.com/patridge/repro-DotnetNewTemplateParameterQuotes

@patridge
Copy link
Contributor Author

I can file it in a separate issue since it's a different OS, but there is a different issue for \" on macOS with .NET Core v2.1.500. This case works, but produces output that is missing multiple other characters, very similar to #1704.

dotnet new repro-quotes-spaces --someparameter="something needing \"escaped quotes\" in it."

Unexpected substitution:

omething needing "escaped quotes" in it

@patridge
Copy link
Contributor Author

Just confirmed the same errors and unexpected outputs on macOS running the same .NET Core and PowerShell Core versions. Editing the initial issue to include that.

The issue seems totally different in Bash, though, as mentioned in the prior comment.

@donJoseLuis donJoseLuis added docs triaged The issue was evaluated by the triage team, placed on correct area, next action defined. and removed Documentation labels Mar 19, 2020
@bekir-ozturk
Copy link
Contributor

Hi @patridge,
This issue will be resolved once we switch to the new command line parser which is planned for .NET 6. You can track the work here #2191.

@vlada-shubina
Copy link
Member

@GangWang01 could you please check if it is fixed? It should be as we already moved to new parser. Thank you

@vlada-shubina vlada-shubina modified the milestones: Backlog, July 2022 Jul 14, 2022
@patridge
Copy link
Contributor Author

@vlada-shubina, @GangWang01
Not sure if I should be on something newer, but I just tested this on dotnet v6.0.302 and it is no longer throwing an error, but it also doesn't work correctly with the escaped characters. The resulting parameter value is never the full, escaped string, and the resulting file only part of the parameter value.

  • For PowerShell-escaped backtick characters
    • dotnet new repro-quotes-spaces --someparameter="something needing "escaped quotes" in it."
    • Resulting variable value: something needing escaped
  • For backslash-escaped characters
    • dotnet new repro-quotes-spaces --someparameter="something needing \"escaped quotes\" in it."
    • Resulting variable value: something needing \escaped
  • For double-quote characters
    • dotnet new repro-quotes-spaces --someparameter="something needing ""escaped quotes"" in it."
    • Resulting variable value: something needing escaped
  • For quotes within apostrophes
    • dotnet new repro-quotes-spaces --someparameter='something needing "escaped quotes" in it.'
    • Resulting variable value: something needing escaped

@vlada-shubina
Copy link
Member

@patridge the fix is potentially available in .NET 7, unfortunately it won't be backported to .NET 6.

@GangWang01
Copy link
Contributor

@patridge @vlada-shubina
It is not reproduced with .NET 7.0.100-preview.6.22352.1.

With Command Prompt on Windows, \ or " can escape quotation mark well. For PowerShell it should be \ or " plus ` together to escape quotation mark, like \`" or `"`" will be escaped as quotation mark.
For other escape characters, they could not escape correctly, but result in being parsed to be multiple arguments passed to the application's entry Main method, then cause the error "Invalid option".

Here are the details using different escape characters with/without space inside.

Command prompt

Input Escape as Expected? Received Parsed Argument
--someparameter="something needing `"escaped quotes`" in it." No --someparameter=something needing `escaped

quotes` in it.
--someparameter="something needing `"escapedquotes`" (without spaces) in it." No --someparameter=something needing `escapedquotes` (without spaces) in it.
--someparameter="something needing \"escaped quotes\" in it." Yes --someparameter=something needing "escaped quotes" in it.
--someparameter="something needing \"escapedquotes\" (without spaces) in it." Yes --someparameter=something needing "escapedquotes" (without spaces) in it.
--someparameter="something needing ""escaped quotes"" in it." Yes --someparameter=something needing "escaped quotes" in it.
--someparameter="something needing ""escapedquotes"" (without spaces) in it." Yes --someparameter=something needing "escapedquotes" (without spaces) in it.
--someparameter='something needing "escaped quotes" in it.' No --someparameter='something

needing

escaped quotes

in

it.'

PowerShell 7

Input Escape as Expected? Received Parsed Argument
--someparameter="something needing `"escaped quotes`" in it." No --someparameter=something needing escaped

quotes in it.
--someparameter="something needing `"escapedquotes`" (without spaces) in it." No --someparameter=something needing escapedquotes (without spaces) in it.
--someparameter="something needing \"escaped quotes\" in it." No --someparameter=something needing \escaped

quotes\ in it.
--someparameter="something needing \"escapedquotes\" (without spaces) in it." No --someparameter=something needing \escapedquotes\ (without spaces) in it.
--someparameter="something needing ""escaped quotes"" in it." No --someparameter=something needing escaped

quotes in it.
--someparameter="something needing ""escapedquotes"" (without spaces) in it." No --someparameter=something needing escapedquotes (without spaces) in it.
--someparameter='something needing "escaped quotes" in it.' No --someparameter=something needing escaped

quotes in it.
--someparameter="something needing \`"escaped quotes\`" in it." Yes --someparameter=something needing "escaped quotes" in it.
--someparameter="something needing \`"escapedquotes\`" (without spaces) in it." Yes --someparameter=something needing "escapedquotes" (without spaces) in it.
--someparameter="something needing `"`"escaped quotes`"`" in it." Yes --someparameter=something needing "escaped quotes" in it.
--someparameter="something needing `"`"escapedquotes`"`" (without spaces) in it." Yes --someparameter=something needing "escapedquotes" (without spaces) in it.

@vlada-shubina vlada-shubina modified the milestones: July 2022, August 2022 Aug 15, 2022
@vlada-shubina
Copy link
Member

Closing, this has been fixed in .NET 7. Correct syntax follows:

Command prompt

--someparameter="something needing \"escaped quotes\" in it."
--someparameter="something needing ""escaped quotes"" in it."

PowerShell 7

--someparameter="something needing \`"escaped quotes\`" in it."
--someparameter="something needing `"`"escaped quotes`"`" in it."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged The issue was evaluated by the triage team, placed on correct area, next action defined.
Projects
None yet
Development

No branches or pull requests

6 participants