Skip to content

Commit

Permalink
fix: Trims trailing slashes from user passed paths that appear before…
Browse files Browse the repository at this point in the history
… query string parameters (#2486)
  • Loading branch information
JonruAlveus authored Jul 15, 2022
1 parent 5cf604b commit 13ba84b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,21 @@ public async Task GetsDirectoryContent()
var contents = await github
.Repository
.Content
.GetAllContentsByRef("octokit", "octokit.net", "Octokit", "master");
.GetAllContentsByRef("octokit", "octokit.net", "Octokit", "main");

Assert.True(contents.Count > 2);
Assert.Equal(ContentType.Dir, contents.First().Type);
}

[IntegrationTest]
public async Task GetsDirectoryContentWithTrailingSlash()
{
var github = Helper.GetAuthenticatedClient();

var contents = await github
.Repository
.Content
.GetAllContentsByRef("octokit", "octokit.net", "Octokit/", "main");

Assert.True(contents.Count > 2);
Assert.Equal(ContentType.Dir, contents.First().Type);
Expand Down
8 changes: 4 additions & 4 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ public static Uri Tree(string owner, string name, string reference)
/// <returns></returns>
public static Uri TreeRecursive(string owner, string name, string reference)
{
return "repos/{0}/{1}/git/trees/{2}?recursive=1".FormatUri(owner, name, reference);
return "repos/{0}/{1}/git/trees/{2}?recursive=1".FormatUri(owner, name, reference.TrimEnd('/'));
}

/// <summary>
Expand Down Expand Up @@ -2445,7 +2445,7 @@ public static Uri RepositoryArchiveLink(string owner, string name, ArchiveFormat
/// <returns>The <see cref="Uri"/> for getting the contents of the specified repository and path</returns>
public static Uri RepositoryContent(string owner, string name, string path, string reference)
{
return "repos/{0}/{1}/contents/{2}?ref={3}".FormatUri(owner, name, path == "/" ? "" : path, reference);
return "repos/{0}/{1}/contents/{2}?ref={3}".FormatUri(owner, name, path == "/" ? "" : path.TrimEnd('/'), reference);
}

/// <summary>
Expand Down Expand Up @@ -3451,7 +3451,7 @@ public static Uri RepositoryContent(long repositoryId, string path)
/// <returns>The <see cref="Uri"/> for getting the contents of the specified repository and path</returns>
public static Uri RepositoryContent(long repositoryId, string path, string reference)
{
return "repositories/{0}/contents/{1}?ref={2}".FormatUri(repositoryId, path, reference);
return "repositories/{0}/contents/{1}?ref={2}".FormatUri(repositoryId, path.TrimEnd('/'), reference);
}

/// <summary>
Expand Down Expand Up @@ -3708,7 +3708,7 @@ public static Uri Tree(long repositoryId, string reference)
/// <returns>The <see cref="Uri"/> for the specified tree.</returns>
public static Uri TreeRecursive(long repositoryId, string reference)
{
return "repositories/{0}/git/trees/{1}?recursive=1".FormatUri(repositoryId, reference);
return "repositories/{0}/git/trees/{1}?recursive=1".FormatUri(repositoryId, reference.TrimEnd('/'));
}

/// <summary>
Expand Down

0 comments on commit 13ba84b

Please sign in to comment.