Skip to content

Commit

Permalink
[bug]: Fixed a bug that content cannot be retrieved if "#" is include…
Browse files Browse the repository at this point in the history
…d in a file or folder name.
  • Loading branch information
minoura-a authored Nov 23, 2022
1 parent 8f01a31 commit 6c11c1e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
25 changes: 25 additions & 0 deletions Octokit.Tests/Helpers/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,30 @@ public void EscapeDoubleQuotesEscapesAllDoubleQuotes()
Assert.Equal("\\\"test milestone\\\"", input.EscapeDoubleQuotes());
}
}

public class EncodeSharpMethod
{
[Fact]
public void EncodeSharpReturnsNullForNullInput()
{
Assert.Equal(string.Empty, (null as string).EncodeSharp());
}

[Fact]
public void EncodeSharpReturnsInputWithoutDoubleQuotes()
{
string input = "some test input without double quotes in it";

Assert.Equal(input, input.EncodeSharp());
}

[Fact]
public void EncodeAllSharp()
{
string input = "#some test input with # in it#";

Assert.Equal("%23some test input with %23 in it%23", input.EncodeSharp());
}
}
}
}
8 changes: 7 additions & 1 deletion Octokit/Helpers/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public static bool IsNotBlank(this string value)
public static Uri FormatUri(this string pattern, params object[] args)
{
Ensure.ArgumentNotNullOrEmptyString(pattern, nameof(pattern));
var uriString = string.Format(CultureInfo.InvariantCulture, pattern, args).EncodeSharp();

return new Uri(string.Format(CultureInfo.InvariantCulture, pattern, args), UriKind.Relative);
return new Uri(uriString, UriKind.Relative);
}

public static string UriEncode(this string input)
Expand Down Expand Up @@ -106,6 +107,11 @@ internal static string EscapeDoubleQuotes(this string value)
return value;
}

internal static string EncodeSharp(this string value)
{
return !string.IsNullOrEmpty(value) ? value?.Replace("#", "%23") : string.Empty;
}

static IEnumerable<string> SplitUpperCase(this string source)
{
Ensure.ArgumentNotNullOrEmptyString(source, nameof(source));
Expand Down

0 comments on commit 6c11c1e

Please sign in to comment.