summaryrefslogtreecommitdiff
path: root/ext/bg/js/json-schema.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-02 10:17:16 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-02 10:17:16 -0500
commit7c9fe2c6cf52e61620ff36853fa0dee1b93594f5 (patch)
tree59d1be2c2f778af802716461ed89572b4ee1f382 /ext/bg/js/json-schema.js
parent964db7410863a5b840b101884c3c522389dd4e80 (diff)
Fix conditional logic
Diffstat (limited to 'ext/bg/js/json-schema.js')
-rw-r--r--ext/bg/js/json-schema.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/ext/bg/js/json-schema.js b/ext/bg/js/json-schema.js
index 65fbce41..97429211 100644
--- a/ext/bg/js/json-schema.js
+++ b/ext/bg/js/json-schema.js
@@ -199,17 +199,19 @@ class JsonSchemaProxyHandler {
}
static validateConditional(value, schema) {
- const ifCondition = schema.if;
- if (!JsonSchemaProxyHandler.isObject(ifCondition)) { return; }
+ const ifSchema = schema.if;
+ if (!JsonSchemaProxyHandler.isObject(ifSchema)) { return; }
- const thenSchema = schema.then;
- if (JsonSchemaProxyHandler.isObject(thenSchema)) {
+ let okay = true;
+ try {
JsonSchemaProxyHandler.validate(value, thenSchema);
+ } catch (e) {
+ okay = false;
}
- const elseSchema = schema.else;
- if (JsonSchemaProxyHandler.isObject(elseSchema)) {
- JsonSchemaProxyHandler.validate(value, thenSchema);
+ const nextSchema = okay ? schema.then : schema.else;
+ if (JsonSchemaProxyHandler.isObject(nextSchema)) {
+ JsonSchemaProxyHandler.validate(value, nextSchema);
}
}