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

Trimming trailing slashes from user passed paths #2486

Merged
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
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