Skip to content
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

proper encoding "+" in package download url #2288

Merged
merged 2 commits into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/Paket.Core/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -735,13 +735,19 @@ let rec private getPackageDetails alternativeProjectRoot root force (sources:Pac
| Some packageDetails -> packageDetails
| Some packageDetails -> packageDetails

let encodeURL (url:string) =
let segments = url.Split [|'?'|]
let baseUrl = segments.[0]
Array.set segments 0 (baseUrl.Replace("+", "%2B"))
("?", segments) |> System.String.Join

let newName = PackageName nugetObject.PackageName
if packageName <> newName then
failwithf "Package details for %O are not matching requested package %O." newName packageName

{ Name = PackageName nugetObject.PackageName
Source = source
DownloadLink = nugetObject.DownloadUrl
DownloadLink = encodeURL nugetObject.DownloadUrl
Unlisted = nugetObject.Unlisted
LicenseUrl = nugetObject.LicenseUrl
DirectDependencies = nugetObject.Dependencies |> Set.ofList }
Expand Down Expand Up @@ -940,15 +946,14 @@ let DownloadPackage(alternativeProjectRoot, root, (source : PackageSource), cach
tracefn "Downloading %O %O%s" packageName version (if groupName = Constants.MainDependencyGroup then "" else sprintf " (%O)" groupName)
let nugetPackage = GetPackageDetails alternativeProjectRoot root force [source] groupName packageName version

let encodeURL (url:string) = url.Replace("+","%2B")
let downloadUri =
if Uri.IsWellFormedUriString(nugetPackage.DownloadLink, UriKind.Absolute) then
Uri nugetPackage.DownloadLink
else
let sourceUrl =
if nugetPackage.Source.Url.EndsWith("/") then nugetPackage.Source.Url
else nugetPackage.Source.Url + "/"
Uri(Uri (encodeURL sourceUrl), encodeURL nugetPackage.DownloadLink)
Uri(Uri sourceUrl, nugetPackage.DownloadLink)

downloadUrl := downloadUri.ToString()

Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/SemVer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ module SemVer =
match firstDash, plusIndex with
| -1, _ -> ""
| d, p when p = -1 -> version.Substring(d+1)
| d, p -> version.Substring(d+1, (version.Length - 1 - p) )
| d, p -> version.Substring(d+1, (p - 1 - d) )

/// there can only be one piece of build metadata, and it is signified by a + and then any number of dot-separated alpha-numeric groups.
/// this just greedily takes the whole remaining string :(
Expand Down