-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow users that have certain special characters in their username to build successfully when using exec #6223
Changes from 5 commits
1314a77
9084023
19c9e4c
94dde5c
7ce00b3
95fca99
34126e1
1c5a2b3
c268b32
7b58784
803cadf
aff3425
6d07c7d
e2d8c0c
828dedc
11c0021
73e8c5c
9cca2db
e05b2e1
ef369fb
ee79111
674dccd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,25 @@ private ExecWrapper PrepareExecWrapper(string command) | |
return exec; | ||
} | ||
|
||
[Fact] | ||
public void EscapeParenthesesInPathToGeneratedBatchFile() | ||
{ | ||
using (var testEnvironment = TestEnvironment.Create()) | ||
{ | ||
// This test counts files in TEMP. If it uses the system TEMP, some | ||
// other process may interfere. Use a private TEMP instead. | ||
var newTempPath = testEnvironment.CreateNewTempPathWithSubfolder("hello()wo(rld)").TempPath; | ||
|
||
string tempPath = Path.GetTempPath(); | ||
Assert.StartsWith(newTempPath, tempPath); | ||
|
||
// Now run the Exec task on a simple command. | ||
Exec exec = PrepareExec("echo Hello World!"); | ||
exec.Execute().ShouldBeTrue(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: no newline |
||
} | ||
} | ||
|
||
/// <summary> | ||
/// Ensures that calling the Exec task does not leave any extra TEMP files | ||
/// lying around. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -611,12 +611,22 @@ protected internal override void AddCommandLineCommands(CommandLineBuilderExtens | |
|
||
// If for some crazy reason the path has a & character and a space in it | ||
// then get the short path of the temp path, which should not have spaces in it | ||
// and then escape the & | ||
if (batchFileForCommandLine.Contains("&") && !batchFileForCommandLine.Contains("^&")) | ||
{ | ||
batchFileForCommandLine = NativeMethodsShared.GetShortFilePath(batchFileForCommandLine); | ||
batchFileForCommandLine = batchFileForCommandLine.Replace("&", "^&"); | ||
} | ||
|
||
StringBuilder fileName = StringBuilderCache.Acquire(batchFileForCommandLine.Length).Append(batchFileForCommandLine); | ||
|
||
// Escape any '(', ')', or '&' | ||
for(int i = 1; i < fileName.Length; i++) | ||
{ | ||
if((fileName[i] == '(' || fileName[i] == ')' || fileName[i] == '&') && fileName[i-1] != '^') | ||
{ | ||
fileName.Insert(i++, '^'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not append each character individually so you don't have to insert into the middle? Also, why not start at 0? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also cache There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not starting at 0 here because we're on windows and |
||
} | ||
} | ||
batchFileForCommandLine = StringBuilderCache.GetStringAndRelease(fileName); | ||
} | ||
|
||
commandLine.AppendFileNameIfNotNull(batchFileForCommandLine); | ||
|
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.
Should we do
"MSBuild", Guid...
so that MSBuild is its own directory, and Guids are subdirectories within it?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.
Also modify any similar methods (if they exist)?
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.
Currently changing the name to MSBuild here works, but there are places where this method could be called instead of Path.GetTempDirectory (even within FileUtilities). Unfortunately this means changing a bunch of tests and I'd rather not piggy-back that onto this PR.
I say we take this change and I can make a new PR that refactors
TempFileUtilities.cs
.If not, I can revert the change to using the MSBuild folder and we can merge this PR as is.
Thoughts?
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 just realized what you were asking for wasn't many
MSBuild<guid>
folders, buttemp/MSBuild/<all the guids folders>
. Given that this commit didn't actually help much, I'm going to revert it and actually fix it in a different PR that's based off of this 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.
sounds great
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.
tracking this here: #6239