Skip to content

Commit f4ebd34

Browse files
committed
Fixed return type
1 parent a3e89ba commit f4ebd34

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/DotNext.Tests/IO/FileUriTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static TheoryData<string, string> GetPaths()
3838
[MemberData(nameof(GetPaths))]
3939
public static void EncodeAsUri(string fileName, string expected)
4040
{
41-
var uri = FileUri.Encode(fileName);
41+
var uri = new Uri(FileUri.Encode(fileName), UriKind.Absolute);
4242
True(uri.IsFile);
4343
Equal(expected, uri.LocalPath);
4444
}

src/DotNext/IO/FileUri.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,20 @@ public static class FileUri
3030
/// </summary>
3131
/// <param name="fileName">The fully-qualified file name.</param>
3232
/// <param name="settings">The encoding settings.</param>
33-
/// <returns><paramref name="fileName"/> as <see cref="Uri"/>.</returns>
33+
/// <returns><paramref name="fileName"/> as URI. The return value can be passed to <see cref="Uri(string)"/> constructor.</returns>
3434
/// <exception cref="ArgumentException"><paramref name="fileName"/> is not fully-qualified.</exception>
35-
public static Uri Encode(ReadOnlySpan<char> fileName, TextEncoderSettings? settings = null)
35+
public static string Encode(ReadOnlySpan<char> fileName, TextEncoderSettings? settings = null)
3636
{
3737
ThrowIfPartiallyQualified(fileName);
3838
var encoder = settings is null ? UrlEncoder.Default : UrlEncoder.Create(settings);
3939
var maxLength = GetMaxEncodedLengthCore(fileName, encoder);
4040
using var buffer = (uint)maxLength <= (uint)SpanOwner<char>.StackallocThreshold
4141
? stackalloc char[maxLength]
4242
: new SpanOwner<char>(maxLength);
43-
44-
TryEncodeCore(fileName, encoder, buffer.Span, out var writtenCount);
45-
return new(buffer.Span.Slice(0, writtenCount).ToString(), UriKind.Absolute);
43+
44+
return TryEncodeCore(fileName, encoder, buffer.Span, out var writtenCount)
45+
? buffer.Span.Slice(0, writtenCount).ToString()
46+
: string.Empty;
4647
}
4748

4849
/// <summary>

0 commit comments

Comments
 (0)