Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Quote package sources that contain spaces (#943)
Browse files Browse the repository at this point in the history
* Escape uris that contain spaces
cannot apply Uri.EscapeUriString blinbdly, or it will double-escape already escaped strings
For #942

* escape with ""

* Use `ArgumentEscaper.EscapeAndConcatenate` which will wrap in quotes if need be
And is generally more detailed and robust than what I  did
see https://github.com/natemcmaster/CommandLineUtils/blob/master/src/CommandLineUtils/Utilities/ArgumentEscaper.cs

Co-authored-by: Anthony Steele <anthony.steele@pockit.com>
  • Loading branch information
AnthonySteele and Anthony Steele committed Apr 29, 2020
1 parent 3a1a0b3 commit 3cfac08
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion NuKeeper.Update/Process/DotNetUpdatePackageCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;
using NuGet.Configuration;
using NuGet.Versioning;
using NuKeeper.Abstractions.NuGet;
Expand All @@ -21,7 +23,7 @@ public DotNetUpdatePackageCommand(IExternalProcess externalProcess)
{
var projectPath = currentPackage.Path.Info.DirectoryName;
var projectFileName = currentPackage.Path.Info.Name;
var sourceUrl = packageSource.SourceUri.ToString();
var sourceUrl = UriEscapedForArgument(packageSource.SourceUri);
var sources = allSources.CommandLine("-s");

var restoreCommand = $"restore {projectFileName} {sources}";
Expand All @@ -36,5 +38,15 @@ public DotNetUpdatePackageCommand(IExternalProcess externalProcess)
var addCommand = $"add {projectFileName} package {currentPackage.Id} -v {newVersion} -s {sourceUrl}";
await _externalProcess.Run(projectPath, "dotnet", addCommand, true);
}

private static string UriEscapedForArgument(Uri uri)
{
if (uri == null)
{
return string.Empty;
}

return ArgumentEscaper.EscapeAndConcatenate(new string[] { uri.ToString() });
}
}
}

0 comments on commit 3cfac08

Please sign in to comment.