Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
escape semicolons when forwarding RestoreSources to MSBuild
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsequitur committed Feb 1, 2017
1 parent 41330f0 commit 7d040fb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ public MSBuildForwardingApp(IEnumerable<string> argsToForward)
{
Type loggerType = typeof(MSBuildLogger);

argsToForward = argsToForward.Concat(new[]
{
$"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}"
});
argsToForward = argsToForward
.Select(Escape)
.Concat(new[]
{
$"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}"
});
}
catch (Exception)
{
Expand Down Expand Up @@ -77,6 +79,11 @@ internal static CommandOption AddVerbosityOption(CommandLineApplication app)
return app.Option("-v|--verbosity", LocalizableStrings.VerbosityOptionDescription, CommandOptionType.SingleValue);
}

private static string Escape(string arg) =>
(arg.StartsWith("/p:RestoreSources=", StringComparison.OrdinalIgnoreCase)) ?
arg.Replace(";", "%3B") : // <-- this is a workaround for https://github.com/Microsoft/msbuild/issues/1622
arg;

private static string GetMSBuildExePath()
{
return Path.Combine(
Expand Down
27 changes: 26 additions & 1 deletion test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.InteropServices;
using FluentAssertions;
using Microsoft.DotNet.Configurer;
using Microsoft.DotNet.Tools.MSBuild;
Expand Down Expand Up @@ -76,6 +77,30 @@ public void When_help_is_invoked_Then_MSBuild_extra_options_text_is_included_in_
}
}

[Fact]
public void WhenRestoreSourcesStartsWithUnixPathThenHttpsSourceIsParsedCorrectly()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return;
}

// this is a workaround for https://github.com/Microsoft/msbuild/issues/1622
var testInstance = TestAssets.Get("MSBuildTestApp")
.CreateInstance()
.WithSourceFiles()
.WithRestoreFiles();

var root = testInstance.Root;
var somePathThatExists = "/usr/local/bin";

var result = new DotnetCommand()
.WithWorkingDirectory(root)
.Execute($"msbuild /p:RestoreSources={somePathThatExists};https://api.nuget.org/v3/index.json /t:restore MSBuildTestApp.csproj");

result.Should().Pass();
}

[Fact]
public void WhenDotnetRunHelpIsInvokedAppArgumentsTextIsIncludedInOutput()
{
Expand All @@ -85,7 +110,7 @@ public void WhenDotnetRunHelpIsInvokedAppArgumentsTextIsIncludedInOutput()
var result = new TestCommand("dotnet")
.WithWorkingDirectory(projectDirectory.Path)
.ExecuteWithCapturedOutput("run --help");

result.ExitCode.Should().Be(0);
result.StdOut.Should().Contain(AppArgumentsText);
}
Expand Down

0 comments on commit 7d040fb

Please sign in to comment.