Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Commit

Permalink
Fix #876, Correct handling of quotation marks in commands
Browse files Browse the repository at this point in the history
- remove extra quotes around `cmd /c` arguments
 - prevented && and similar special cases
- don't strip quotes surrounding command-line arguments
 - prevented command paths and arguments containing spaces

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

nit:
- let VS do its thing with test services
  • Loading branch information
dougbu committed May 24, 2015
1 parent acb75f0 commit d8cb409
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public CommandGrammar(Func<string, string> variable)
var environmentVariablePiece = Ch('%').And(Rep(Ch().Not(Ch('%')))).And(Ch('%')).Left().Down().Str()
.Build(key => variable(key) ?? "%" + key + "%");

var escapeSequencePiece =
var escapeSequencePiece =
Ch('%').And(Ch('%')).Build(_=>"%")
.Or(Ch('^').And(Ch('^')).Build(_ => "^"))
.Or(Ch('\\').And(Ch('\\')).Build(_ => "\\"))
Expand All @@ -29,7 +29,9 @@ public CommandGrammar(Func<string, string> variable)

var unquotedTerm = Rep1(unquotedPiece.Or(specialPiece)).Str();

var quotedTerm = Ch('\"').And(Rep(quotedPiece.Or(specialPiece)).Str()).And(Ch('\"')).Left().Down();
var quotedTerm = Ch('\"').And(Rep(quotedPiece.Or(specialPiece)).Str()).And(Ch('\"'))
.Left().Down()
.Build(str => "\"" + str + "\"");

var whitespace = Rep(Ch(' '));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public bool Execute(Runtime.Project project, string scriptName, Func<string, str
if (!PlatformHelper.IsMono)
{
// Forward-slash is used in script blocked only. Replace them with back-slash to correctly
// locate the script. The directory separator is platform-specific.
// locate the script. The directory separator is platform-specific.
scriptArguments[0] = scriptArguments[0].Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);

// Command-lines on Windows are executed via "cmd /C" in order
Expand All @@ -59,9 +59,8 @@ public bool Execute(Runtime.Project project, string scriptName, Func<string, str
if (!string.IsNullOrEmpty(comSpec))
{
scriptArguments =
new[] { comSpec, "/C", "\"" }
new[] { comSpec, "/C" }
.Concat(scriptArguments)
.Concat(new[] { "\"" })
.ToArray();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

0 comments on commit d8cb409

Please sign in to comment.