mirror of
https://github.com/tristanpenman/valijson.git
synced 2024-12-13 10:32:58 +01:00
Tweak behaviour of format constraint validation
This commit is contained in:
parent
92b9514bde
commit
138c3785ef
@ -356,6 +356,25 @@ public:
|
||||
*/
|
||||
bool visit(const FormatConstraint &constraint) override
|
||||
{
|
||||
//
|
||||
// Don't attempt to cast validate the format constraint unless the
|
||||
// target value is known to be a string. Drafts 4-7 of the spec
|
||||
// suggest that 'format' should be treated as an annotation rather
|
||||
// than an assertion, however this is not guaranteed. Given that we
|
||||
// have been treating it as an assertion here, failing quietly on
|
||||
// non-string values seems like the right thing to do, to avoid
|
||||
// this throwing an exception.
|
||||
//
|
||||
// Schemas that need tighter validation around 'format' constaints
|
||||
// should generally pair it with a 'type' constraint.
|
||||
//
|
||||
// Reference:
|
||||
// https://json-schema.org/understanding-json-schema/reference/string.html#format
|
||||
//
|
||||
if (!m_target.maybeString()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string s = m_target.asString();
|
||||
const std::string format = constraint.getFormat();
|
||||
if (format == "date") {
|
||||
|
Loading…
Reference in New Issue
Block a user