diff --git a/src/NJsonSchema.Tests/Validation/SchemaTests.cs b/src/NJsonSchema.Tests/Validation/SchemaTests.cs
index d16e59279..cc2b3227d 100644
--- a/src/NJsonSchema.Tests/Validation/SchemaTests.cs
+++ b/src/NJsonSchema.Tests/Validation/SchemaTests.cs
@@ -379,5 +379,37 @@ public async Task When_multiple_types_fail_with_errors_take_the_best_group()
Assert.Equal(1, errors.Count);
Assert.Contains(errors, e => e.Kind == ValidationErrorKind.NoTypeValidates);
}
+
+ [Fact]
+ public async Task When_datetime_with_regex_validation_then_datetime_is_not_altered()
+ {
+ //// Arrange
+ var schemaJson = @"
+ {
+ ""$schema"": ""http://json-schema.org/draft-07/schema#"",
+ ""type"": ""object"",
+ ""required"": [
+ ""my_datetime""
+ ],
+ ""properties"": {
+ ""my_datetime"": {
+ ""type"": ""string"",
+ ""pattern"": ""^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$""
+ }
+ }
+ }";
+
+ var json = @"
+ {
+ ""my_datetime"": ""2018-12-19T16:58:07.270Z""
+ }";
+
+ //// Act
+ var schema = await JsonSchema4.FromJsonAsync(schemaJson);
+ var errors = schema.Validate(json);
+
+ //// Assert
+ Assert.Equal(0, errors.Count);
+ }
}
}
diff --git a/src/NJsonSchema/Validation/JsonSchemaValidator.cs b/src/NJsonSchema/Validation/JsonSchemaValidator.cs
index 3f78cb2cd..fa8b724fc 100644
--- a/src/NJsonSchema/Validation/JsonSchemaValidator.cs
+++ b/src/NJsonSchema/Validation/JsonSchemaValidator.cs
@@ -8,6 +8,7 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
@@ -52,8 +53,15 @@ public JsonSchemaValidator()
/// The list of validation errors.
public ICollection Validate(string jsonData, JsonSchema4 schema)
{
- var jsonObject = JToken.Parse(jsonData);
- return Validate(jsonObject, schema);
+ using (var reader = new StringReader(jsonData))
+ using (var jsonReader = new JsonTextReader(reader)
+ {
+ DateParseHandling = DateParseHandling.None
+ })
+ {
+ var jsonObject = JToken.ReadFrom(jsonReader);
+ return Validate(jsonObject, schema);
+ }
}
/// Validates the given JSON token.