diff --git a/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/UrlAttribute.cs b/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/UrlAttribute.cs index 91e8e40494f034..830b36fcbbdd48 100644 --- a/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/UrlAttribute.cs +++ b/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/UrlAttribute.cs @@ -19,7 +19,7 @@ public override bool IsValid(object? value) { switch (value) { - case Uri valueAsUri: + case Uri valueAsUri when valueAsUri.IsAbsoluteUri: { return valueAsUri.Scheme == Uri.UriSchemeHttp || valueAsUri.Scheme == Uri.UriSchemeHttps diff --git a/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/UrlAttributeTests.cs b/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/UrlAttributeTests.cs index 0b674ddff6d3e5..e137ce077e636d 100644 --- a/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/UrlAttributeTests.cs +++ b/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/UrlAttributeTests.cs @@ -26,6 +26,8 @@ protected override IEnumerable InvalidValues() yield return new TestCase(new UrlAttribute(), new object()); yield return new TestCase(new UrlAttribute(), new Uri("file:///foo.bar")); yield return new TestCase(new UrlAttribute(), new Uri("//foo.png")); + yield return new TestCase(new UrlAttribute(), new Uri("/foo.png", UriKind.RelativeOrAbsolute)); + yield return new TestCase(new UrlAttribute(), new Uri("foo.png", UriKind.Relative)); } [Fact]