-
Notifications
You must be signed in to change notification settings - Fork 228
Fix #876, Correct handling of quotation marks in commands #1931
Conversation
/cc @davidfowl
|
4c0daa8
to
2a5aaac
Compare
@davidfowl since you like to look at individual commits, I rebased and added a couple more 😺 Latest version is more resilient and I've tested it numerous ways -- manually. |
2a5aaac
to
d0252a1
Compare
Rebased again and added tests. @davidfowl |
@dougbu This is broken on *nix. Look at travis |
|
||
[ConditionalTheory] | ||
[MemberData(nameof(RuntimeComponents))] | ||
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] |
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.
Why?
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.
Because i am positive my bash
-writing skills are out-of-date and don't have a Linux system to play on. We can follow-up later with additional scripts.
@davidfowl Travis builds now successful |
Should have mentioned: No regressions on Mac or Linux |
d16f9ca
to
9c365ff
Compare
|
||
Assert.Equal(0, exitCode); | ||
Assert.Empty(error); | ||
Assert.Equal(expectedOutput, output); |
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.
DNX_TRACE
is turned on by default in our TeamCity CI and you'll get extra info in output.
Use Assert.Contains()
or turn off DNX_TRACE
in the subprocess with something like:
https://github.com/aspnet/dnx/blob/dev/test/Bootstrapper.FunctionalTests/BootstrapperTests.cs#L114
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.
🆗 I turned off DNX_TRACE
for other added tests in this PR. Will do the same here.
args[index] = arg.Substring(1, arg.Length - 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.
As @davidfowl and I discussed, will undo this change.
af4b0aa
to
96f85ca
Compare
scriptArguments = new[] { "/bin/bash", "-c", "\"" } | ||
.Concat(scriptArguments.Select(argument => argument.Replace("\"", "\\\""))) | ||
.Concat(new[] { "\"" }) | ||
.ToArray(); | ||
} |
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.
/cc @troydai I fixed the problems in this else
block that we discussed today. E.g. code no longer checks for the script file in whatever random directory dnu
was executing.
@davidfowl rebased, updated, and working on Linux. (Not sure why the Travix-ci/pr build hung but the push build succeeded.) |
// Special-case a script name that, perhaps with added .sh, matches an existing file. | ||
var surroundWithQuotes = false; | ||
var scriptCandidate = scriptArguments[0]; | ||
if (scriptCandidate.StartsWith("\"", StringComparison.Ordinal) && |
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.
Can you have spaces before the first quote or after the last one?
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.
That's possible in the project.json file. But CommandGrammar
removes spaces between and before all arguments and ignores the (remote) possibility of an argument that contains more than a correctly-quoted string.
Looks good to me and I only had the two comments above |
- don't strip quotes surrounding command-line arguments when used in `scripts` - prevented command paths and grouping arguments containing spaces - pass `preserveSurroundingQuotes` into `CommandGrammar` to control stripping - support expected shell capabilities such as quoting command and redirections - use `cmd /s /c` when executing `scripts` on Windows - use `/bin/bash -c` when executing `scripts` on Linux - add functional tests of commands and scripts (together with `dnu restore`) - no `dnu restore` for .NET Core due to extra time required note: - `CommandGrammar` may need additional generalizations - e.g. unquoted term can't contain more than one escape sequence - but it's probably good enough for now - _not_ adding quotes around variables replacements inserted into commands - no way of determining if replacement is already quoted - basically, leave it to project.json author to perform appropriate quoting for their platform nits: - let VS do its thing with test services - make `CommandGrammar` constructor private; used only in `Process()` method - update a few `ScriptExecutor` comments, long lines, et cetera
96f85ca
to
90f1f03
Compare
scripts
preserveSurroundingQuotes
intoCommandGrammar
to control strippingcmd /s /c
when executingscripts
on Windows/bin/bash -c
when executingscripts
on Linuxdnu restore
)dnu restore
for .NET Core due to extra time requirednote:
CommandGrammar
may need additional generalizationsnits:
let VS do its thing with test servicesCommandGrammar
constructor private; used only inProcess()
methodScriptExecutor
comments, long lines, et cetera