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

Commit

Permalink
(GH-84) Escape branch uri value so prevent 404 on pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiringWorm committed Aug 2, 2019
1 parent b6945c7 commit b7ececb
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Source/Codecov/Url/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ private static string EscapeKnownProblematicCharacters(string data)
return result.ToString();
}

private void OverrideIfNotEmptyOrNull(string key, string value)
private void OverrideIfNotEmptyOrNull(string key, string value, bool escapeValue = false)
{
if (!string.IsNullOrWhiteSpace(value))
{
QueryParameters[key] = value.RemoveAllWhiteSpace();
QueryParameters[key] = escapeValue ?
Uri.EscapeDataString(value.RemoveAllWhiteSpace()) :
value.RemoveAllWhiteSpace();
}
}

Expand All @@ -77,8 +79,8 @@ private void SetBranch()
if (!string.IsNullOrWhiteSpace(repository.Branch))
{
// We also need to take into account that '#' needs to be escaped for parameters
// to work, but not '/'
QueryParameters["branch"] = EscapeKnownProblematicCharacters(repository.Branch);
var escapedBranch = EscapeKnownProblematicCharacters(Uri.EscapeDataString(repository.Branch));
QueryParameters["branch"] = escapedBranch;
break;
}
}
Expand All @@ -88,7 +90,9 @@ private void SetBranch()

private void SetBuild()
{
QueryParameters["build"] = Build.Build;
var escapedBuild = Uri.EscapeDataString(Build.Build);

QueryParameters["build"] = escapedBuild;
OverrideIfNotEmptyOrNull("build", Options.Build);
}

Expand Down

0 comments on commit b7ececb

Please sign in to comment.