Skip to content

Commit

Permalink
Merge pull request #895 from naveensrinivasan/master
Browse files Browse the repository at this point in the history
Fix for Upload to Github releases stopped working #894
  • Loading branch information
haacked committed Sep 17, 2015
2 parents c6c332f + f000980 commit 32c154f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Octokit.Tests/Helpers/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ public class TheExpandUriTemplateMethod
[InlineData("https://host.com/path?name=other", "https://host.com/path?name=other")]
[InlineData("https://host.com/path?name=example name.txt", "https://host.com/path{?name}")]
[InlineData("https://host.com/path", "https://host.com/path{?other}")]
[InlineData("https://host.com/path?name=example name.txt&label=labeltext", "https://host.com/path{?name,label}")]
[InlineData("https://host.com/path?name=example name.txt&label=labeltext", "https://host.com/path{?name,label,other}")]
public void ExpandsUriTemplates(string expected, string template)
{
Assert.Equal(expected, template.ExpandUriTemplate(new { name = "example name.txt" }).ToString());
Assert.Equal(expected, template.ExpandUriTemplate(new { name = "example name.txt",label="labeltext" }).ToString());
}
}
}
Expand Down
18 changes: 12 additions & 6 deletions Octokit/Helpers/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,20 @@ public static string FromBase64String(this string encoded)
public static Uri ExpandUriTemplate(this string template, object values)
{
var optionalQueryStringMatch = _optionalQueryStringRegex.Match(template);
if(optionalQueryStringMatch.Success)
if (optionalQueryStringMatch.Success)
{
var expansion = "";
var parameterName = optionalQueryStringMatch.Groups[1].Value;
var parameterProperty = values.GetType().GetProperty(parameterName);
if(parameterProperty != null)
var expansion = string.Empty;
var parameters = optionalQueryStringMatch.Groups[1].Value.Split(new char[] { ',' });

foreach (var parameter in parameters)
{
expansion = "?" + parameterName + "=" + Uri.EscapeDataString("" + parameterProperty.GetValue(values, new object[0]));
var parameterProperty = values.GetType().GetProperty(parameter);
if (parameterProperty != null)
{
expansion += string.IsNullOrWhiteSpace(expansion) ? "?" : "&";
expansion += parameter + "=" +
Uri.EscapeDataString("" + parameterProperty.GetValue(values, new object[0]));
}
}
template = _optionalQueryStringRegex.Replace(template, expansion);
}
Expand Down

0 comments on commit 32c154f

Please sign in to comment.