Skip to content

Commit 9f290a0

Browse files
author
Maksim Golev
committed
feat(#71008): Add Uri support.
1 parent b484b14 commit 9f290a0

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ public override bool IsValid(object? value)
1919
{
2020
switch (value)
2121
{
22+
case Uri valueAsUri:
23+
{
24+
return valueAsUri.Scheme == Uri.UriSchemeHttp
25+
|| valueAsUri.Scheme == Uri.UriSchemeHttps
26+
|| valueAsUri.Scheme == Uri.UriSchemeFtp;
27+
}
2228
case string valueAsString:
2329
{
2430
return valueAsString.StartsWith("http://", StringComparison.OrdinalIgnoreCase)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ protected override IEnumerable<TestCase> ValidValues()
1414
yield return new TestCase(new UrlAttribute(), "http://foo.bar");
1515
yield return new TestCase(new UrlAttribute(), "https://foo.bar");
1616
yield return new TestCase(new UrlAttribute(), "ftp://foo.bar");
17+
yield return new TestCase(new UrlAttribute(), new Uri("http://foo.bar"));
18+
yield return new TestCase(new UrlAttribute(), new Uri("https://foo.bar"));
19+
yield return new TestCase(new UrlAttribute(), new Uri("ftp://foo.bar"));
1720
}
1821

1922
protected override IEnumerable<TestCase> InvalidValues()
2023
{
2124
yield return new TestCase(new UrlAttribute(), "file:///foo.bar");
2225
yield return new TestCase(new UrlAttribute(), "foo.png");
2326
yield return new TestCase(new UrlAttribute(), new object());
27+
yield return new TestCase(new UrlAttribute(), new Uri("file:///foo.bar"));
28+
yield return new TestCase(new UrlAttribute(), new Uri("//foo.png"));
2429
}
2530

2631
[Fact]

0 commit comments

Comments
 (0)