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
17 changes: 17 additions & 0 deletions src/NJsonSchema.Tests/Validation/FormatUriTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,22 @@ public void When_format_uri_correct_then_validation_succeeds()
// Assert
Assert.Empty(errors);
}

[Fact]
public void When_uri_token_is_of_type_uri_then_validation_succeeds()
{
// Arrange
var schema = new JsonSchema();
schema.Type = JsonObjectType.String;
schema.Format = JsonFormatStrings.Uri;

var token = new JValue(new Uri("http://rsuter.com"));

// Act
var errors = schema.Validate(token);

// Assert
Assert.Empty(errors);
}
}
}
9 changes: 6 additions & 3 deletions src/NJsonSchema/Validation/JsonSchemaValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,12 @@ private void ValidateString(JToken token, JsonSchema schema, JsonObjectType type

if (isString)
{
var value = token.Type == JTokenType.Date && token is JValue jValue
? jValue.ToString("yyyy-MM-ddTHH:mm:ssK", CultureInfo.InvariantCulture)
: token.Value<string>();
var value = token.Type switch
{
JTokenType.Date => (token as JValue)?.ToString("yyyy-MM-ddTHH:mm:ssK", CultureInfo.InvariantCulture),
JTokenType.Uri => (token as JValue)?.ToString(CultureInfo.InvariantCulture),
_ => token.Value<string>()
};

if (value != null)
{
Expand Down