Skip to content

Commit 4cdd36a

Browse files
committed
correctly handling escaping
1 parent a7ab7fa commit 4cdd36a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Client/ApiCredentials.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public record ApiCredentials(string User, string Password)
2525
return null;
2626

2727
var parts = uri.UserInfo.Split(':', 2);
28-
return new ApiCredentials(parts[0], parts.Length > 1 ? parts[1] : string.Empty);
28+
29+
return new ApiCredentials(
30+
Uri.UnescapeDataString(parts[0]),
31+
parts.Length > 1 ? Uri.UnescapeDataString(parts[1]) : string.Empty);
2932
}
3033
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using FluentAssertions;
3+
using Xunit;
4+
5+
namespace Beefweb.Client;
6+
7+
public class ApiCredentialsTests
8+
{
9+
[Fact]
10+
public void FromUri_UnescapesValues()
11+
{
12+
const string userName = "User#";
13+
const string password = "P@ssword";
14+
15+
var builder = new UriBuilder("http://localhost")
16+
{
17+
UserName = userName,
18+
Password = password
19+
};
20+
21+
var uri = builder.Uri;
22+
var credentials = ApiCredentials.FromUri(uri);
23+
credentials.Should().NotBeNull();
24+
credentials!.User.Should().Be(userName);
25+
credentials.Password.Should().Be(password);
26+
}
27+
}

0 commit comments

Comments
 (0)