diff --git a/README.md b/README.md index 32af42b..5b064f3 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ int main(void) } ``` -# Conformity +# Compliance There is an application which can be used for testing the validator with the [JSON-Schema-Test-Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite). @@ -121,10 +121,9 @@ There is an application which can be used for testing the validator with the If you have cloned this repository providing a path the repository-root via the cmake-variable `JSON_SCHEMA_TEST_SUITE_PATH` will enable the test-target(s). -Currently **31** of **304** tests are failing: +Currently **28** of **304** tests are failing: - 22 of them are `format`-strings which are not supported. -- 3 of them are because `pattern` is not implemented for strings - and 6 bugs - unicode string length (2x) - multipleOf with fractional numbers (how the heck does fmod work?) (1) diff --git a/src/json-validator.cpp b/src/json-validator.cpp index 43144bb..c5b5ac5 100644 --- a/src/json-validator.cpp +++ b/src/json-validator.cpp @@ -173,9 +173,8 @@ void validate_enum(json &instance, const json &schema, const std::string &name) void validate_string(json &instance, const json &schema, const std::string &name) { - // possibile but unhanled keywords + // possible but unhandled keywords not_yet_implemented(schema, "format", "string"); - not_yet_implemented(schema, "pattern", "string"); validate_type(schema, "string", name); @@ -198,6 +197,13 @@ void validate_string(json &instance, const json &schema, const std::string &name << attr.value() << ")"; throw std::out_of_range(s.str()); } + + attr = schema.find("pattern"); + if (attr != schema.end()) { + std::regex re(attr.value().get(), std::regex::ECMAScript); + if (!std::regex_search(instance.get(), re)) + throw std::invalid_argument(instance.get() + " does not match regex pattern: " + attr.value().get()); + } } void validate_boolean(json & /*instance*/, const json &schema, const std::string &name)