Skip to content

Commit ded76db

Browse files
committed
Preserve trailing slash in file spec for directory
This enhances consistency with the `/` meaning "start relative path from here on", which can now be used consistently in both the path and url.
1 parent dd8024d commit ded76db

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/File/FileSpec.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,22 @@ public FileSpec(string path, Uri? uri = null, string? etag = null, string? sha =
106106
Sha = sha;
107107
NewSha = sha;
108108

109-
if (!finalPath && uri != null &&
109+
if (!finalPath && uri != null && !uri.AbsolutePath.EndsWith('/') &&
110110
(path.EndsWith('\\') || path.EndsWith('/')))
111111
{
112112
path = System.IO.Path.Combine(path, WithDefaultPath(uri!).Path);
113113
}
114114

115115
// This will also normalize double slashes.
116-
var parts = path.Split(new[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries);
116+
var parts = path.Split(['\\', '/'], StringSplitOptions.RemoveEmptyEntries);
117117
if (parts.Length > 0 && parts[0] == ".")
118118
Path = string.Join('/', parts.Skip(1));
119119
else
120120
Path = string.Join('/', parts);
121+
122+
// Preserve trailing slash if present, for consistency with url ending in /.
123+
if (path.EndsWith('/') || path.EndsWith("\\"))
124+
Path += "/";
121125
}
122126

123127
public string Path { get; }

src/File/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static async Task<int> Main(string[] args)
5959
}
6060

6161
// Try to pair Uri+File to allow intuitive download>path mapping, such as
62-
// https://gitub.com/org/repo/docs/file.md docs/file.md
62+
// https://gitub.com/org/repo/docs/file.md > docs/file.md
6363
if (Uri.TryCreate(extraArgs[i], UriKind.Absolute, out var uri))
6464
{
6565
var next = i + 1;

0 commit comments

Comments
 (0)