-
Notifications
You must be signed in to change notification settings - Fork 382
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
Fix #1385 #1390
Fix #1385 #1390
Conversation
@@ -25,52 +27,66 @@ public IEnumerable<string> Split(string commandLine) | |||
var pos = 0; | |||
|
|||
var seeking = Boundary.TokenStart; | |||
int? skipQuoteAtIndex = null; | |||
var seekingQuote = Boundary.QuoteStart; | |||
StringBuilder sb = new StringBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perf challenge #2: Can you do it without the StringBuilder
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StringBuilder removed and code modified accordingly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful! Nice work!
Optimizing string operations
Thanks, @krsahab! |
|
||
_splitter.Split(commandLine) | ||
.Should() | ||
.BeEquivalentTo("POST", "--raw='{Id:1,Name:Alice}'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. The double quotes should be preserved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minimal Changes have been done just to fix the mentioned issue and not to modify any existing logic.
It was preexisting logic to stripe away all the double-quotes. I tried to preserve it but it was conflicting with other test cases.
In scenarios such as a simple REPL (https://github.com/database64128/DotnetPlayground/blob/main/CommandLinePlayground/Program.cs#L35), one would expect that each argument was parsed as is. Currently all double quotes are striped away. An input string such as |
As per preexisting logic, only double quotes should be removed, not any other characters (whitespace is a special case). If single quotes should be removed, then the question is What all characters should be removed or preserved? |
@krsahab Thank you for the explanation! Maybe I should open a new issue for my proposed changes.
I think the behavior should be aligned with popular shells: Remove the outermost pair of quotes. |
The behavior is intended to match this: https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-commandlinetoargvw. I'm sure we've missed some details. This is separate from the shell behavior. Different shells have their own escaping rules, so in many cases the application entry point might never even see the quotes you typed into the terminal. |
Fix for issue #1385
Ignore whitespace inside the quote
Ignore quotes if seeking == Boundary.WordEnd
Tests added