-
Notifications
You must be signed in to change notification settings - Fork 104
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
Improve command line argument quoting logic #335
base: master
Are you sure you want to change the base?
Improve command line argument quoting logic #335
Conversation
…age and no files generated. After troubleshooting I root-caused the issue to .NET command line parsing rules, where special characters like double-quotes and backslashes have to be escaped under some circumstances. There already was a code to handle some of these cases, but it didn't cover the following: 1) When there are multiple backslashes preceeding the double-quote, we need to escape all of them, not only the last one. 2) When there is a backslash at the end of the argument, we need to escape it, otherwise it will escape the double-quote appended by the code itself, causing attribute value to run out when parsed by .NET infrastructure. This change is improving the logic to account for these two extra cases. I also added unit tests to demonstrate the behavior. In order to do so, I had to move the JoinArguments methd to a public helper class, so that it can be accessed from unit tests, as I'm not a big fan of InternalsVisibleTo.
} | ||
|
||
// escape backslashes appearing before a double quote or end of line by doubling them | ||
string arg = Regex.Replace(argument, @"(\\+)(""|$)", "$1$1$2"); |
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.
If you don't want tests/new helper class, then all it takes to fix it is to replace this line in the original method.
I don't mind adding a new class and test project, but we definitely want IVT to the test project and change the helper class to |
…y using InternalsVisibleTo attribute
Done. Luckily there was already a signing key for test assemblies, so I didn't have to add a new one. |
We hit an issue where C# generator tool would exit with no error message and no files generated.
After troubleshooting I root-caused the issue to .NET command line parsing rules, where special characters like double-quotes and backslashes have to be escaped under some circumstances.
There already was a code to handle some of these cases, but it didn't cover the following:
This change is improving the logic to account for these two extra cases. I also added unit tests to demonstrate the behavior. In order to do so, I had to move the JoinArguments method to a public helper class, so that it can be accessed from unit tests, as I'm not a big fan of InternalsVisibleTo.