Skip to content

Commit 4a75bea

Browse files
authored
Fix UrlAttribute handling of relative Uris (#115234)
* Update UrlAttribute.cs * Update UrlAttributeTests.cs * Fix the test
1 parent d57b9d6 commit 4a75bea

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/UrlAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public override bool IsValid(object? value)
1919
{
2020
switch (value)
2121
{
22-
case Uri valueAsUri:
22+
case Uri valueAsUri when valueAsUri.IsAbsoluteUri:
2323
{
2424
return valueAsUri.Scheme == Uri.UriSchemeHttp
2525
|| valueAsUri.Scheme == Uri.UriSchemeHttps

src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/UrlAttributeTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ protected override IEnumerable<TestCase> InvalidValues()
2626
yield return new TestCase(new UrlAttribute(), new object());
2727
yield return new TestCase(new UrlAttribute(), new Uri("file:///foo.bar"));
2828
yield return new TestCase(new UrlAttribute(), new Uri("//foo.png"));
29+
yield return new TestCase(new UrlAttribute(), new Uri("/foo.png", UriKind.RelativeOrAbsolute));
30+
yield return new TestCase(new UrlAttribute(), new Uri("foo.png", UriKind.Relative));
2931
}
3032

3133
[Fact]

0 commit comments

Comments
 (0)