Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,29 @@ public UrlAttribute()

public override bool IsValid(object? value)
{
if (value == null)
switch (value)
{
return true;
case Uri valueAsUri:
{
return valueAsUri.Scheme == Uri.UriSchemeHttp
|| valueAsUri.Scheme == Uri.UriSchemeHttps
|| valueAsUri.Scheme == Uri.UriSchemeFtp;
}
case string valueAsString:
{
return valueAsString.StartsWith("http://", StringComparison.OrdinalIgnoreCase)
|| valueAsString.StartsWith("https://", StringComparison.OrdinalIgnoreCase)
|| valueAsString.StartsWith("ftp://", StringComparison.OrdinalIgnoreCase);
}
case null:
{
return true;
}
default:
{
return false;
}
}

return value is string valueAsString &&
(valueAsString.StartsWith("http://", StringComparison.OrdinalIgnoreCase)
|| valueAsString.StartsWith("https://", StringComparison.OrdinalIgnoreCase)
|| valueAsString.StartsWith("ftp://", StringComparison.OrdinalIgnoreCase));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ protected override IEnumerable<TestCase> ValidValues()
yield return new TestCase(new UrlAttribute(), "http://foo.bar");
yield return new TestCase(new UrlAttribute(), "https://foo.bar");
yield return new TestCase(new UrlAttribute(), "ftp://foo.bar");
yield return new TestCase(new UrlAttribute(), new Uri("http://foo.bar"));
yield return new TestCase(new UrlAttribute(), new Uri("https://foo.bar"));
yield return new TestCase(new UrlAttribute(), new Uri("ftp://foo.bar"));
}

protected override IEnumerable<TestCase> InvalidValues()
{
yield return new TestCase(new UrlAttribute(), "file:///foo.bar");
yield return new TestCase(new UrlAttribute(), "foo.png");
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"));
}

[Fact]
Expand Down
Loading