Fix #4139 - escape quoted strings for process start

This commit is contained in:
Nate McMaster 2018-03-08 15:50:33 -08:00 committed by Peter Huene
parent 9cc2b7cd2f
commit ba8e18dac7
No known key found for this signature in database
GPG key ID: E1D265D820213D6A
3 changed files with 27 additions and 7 deletions

View file

@ -0,0 +1,25 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests
{
public class ArgumentEscaperTests
{
[Theory]
[InlineData(new[] { "one", "two", "three" }, "one two three")]
[InlineData(new[] { "line1\nline2", "word1\tword2" }, "\"line1\nline2\" \"word1\tword2\"")]
[InlineData(new[] { "with spaces" }, "\"with spaces\"")]
[InlineData(new[] { @"with\backslash" }, @"with\backslash")]
[InlineData(new[] { @"""quotedwith\backslash""" }, @"\""quotedwith\backslash\""")]
[InlineData(new[] { @"C:\Users\" }, @"C:\Users\")]
[InlineData(new[] { @"C:\Program Files\dotnet\" }, @"""C:\Program Files\dotnet\\""")]
[InlineData(new[] { @"backslash\""preceedingquote" }, @"backslash\\\""preceedingquote")]
[InlineData(new[] { @""" hello """ }, @"""\"" hello \""""")]
public void EscapesArgumentsForProcessStart(string[] args, string expected)
{
Assert.Equal(expected, ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(args));
}
}
}