validator: pattern-field implemented
This commit is contained in:
parent
de05d4d754
commit
5fedc283da
@ -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)
|
||||
|
||||
@ -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::string>(), std::regex::ECMAScript);
|
||||
if (!std::regex_search(instance.get<std::string>(), re))
|
||||
throw std::invalid_argument(instance.get<std::string>() + " does not match regex pattern: " + attr.value().get<std::string>());
|
||||
}
|
||||
}
|
||||
|
||||
void validate_boolean(json & /*instance*/, const json &schema, const std::string &name)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user