Skip to content

Commit a9a3339

Browse files
bart-vmwareTimHess
authored andcommitted
Add optimized path when no comma in URL
1 parent c5d4a94 commit a9a3339

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

src/Common/src/Common/Extensions/UriExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public static string ToMaskedString(this Uri source)
4141
}
4242

4343
var uris = source.ToString();
44+
45+
if (!uris.Contains(','))
46+
{
47+
return source.ToMaskedUri().ToString();
48+
}
49+
4450
return string.Join(",", uris.Split(_uriSeparatorChar, StringSplitOptions.RemoveEmptyEntries).Select(uri => new Uri(uri).ToMaskedUri().ToString()));
4551
}
4652

src/Common/test/Common.Test/Extensions/UriExtensionsTest.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,29 @@ namespace Steeltoe.Common.Test.Extensions;
1111
public class UriExtensionsTest
1212
{
1313
[Fact]
14-
public void MaskExistingBasicAuthentication()
14+
public void MaskSingleBasicAuthentication()
15+
{
16+
var uri = new Uri("http://username:password@www.example.com/");
17+
const string expected = "http://****:****@www.example.com/";
18+
19+
var masked = uri.ToMaskedString();
20+
21+
Assert.Equal(expected, masked);
22+
}
23+
24+
[Fact]
25+
public void MaskMultiBasicAuthentication()
1526
{
1627
var uri = new Uri("http://username:password@www.example.com/,http://user2:pass2@www.other.com/");
17-
var expected = "http://****:****@www.example.com/,http://****:****@www.other.com/";
28+
const string expected = "http://****:****@www.example.com/,http://****:****@www.other.com/";
1829

1930
var masked = uri.ToMaskedString();
2031

2132
Assert.Equal(expected, masked);
2233
}
2334

2435
[Fact]
25-
public void DontMaskIfNotBasicAuthenticationExists()
36+
public void DoNotMaskIfNoBasicAuthentication()
2637
{
2738
var uri = new Uri("http://www.example.com/");
2839
var expected = uri.ToString();
@@ -31,4 +42,4 @@ public void DontMaskIfNotBasicAuthenticationExists()
3142

3243
Assert.Equal(expected, masked);
3344
}
34-
}
45+
}

0 commit comments

Comments
 (0)