gluon-web: javascript: don't use global RegExp.$x matches, fix "this" for parameterized validators

Doing so caused broken validations, as different validators were affecting
each other.
This commit is contained in:
Matthias Schiffer 2017-03-10 22:20:34 +01:00
parent ca5e1f8b75
commit da19961188
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C
2 changed files with 12 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@ -53,11 +53,12 @@
}, },
'ip4addr': function() { 'ip4addr': function() {
if (this.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)) { var match;
return (RegExp.$1 >= 0) && (RegExp.$1 <= 255) && if ((match = this.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/))) {
(RegExp.$2 >= 0) && (RegExp.$2 <= 255) && return (match[1] >= 0) && (match[1] <= 255) &&
(RegExp.$3 >= 0) && (RegExp.$3 <= 255) && (match[2] >= 0) && (match[2] <= 255) &&
(RegExp.$4 >= 0) && (RegExp.$4 <= 255); (match[3] >= 0) && (match[3] <= 255) &&
(match[4] >= 0) && (match[4] <= 255);
} }
return false; return false;
@ -128,14 +129,14 @@
}; };
function compile(type) { function compile(type) {
var v; var v, match;
if (type.match(/^([^\(]+)\(([^,]+),([^\)]+)\)$/) && (v = validators[RegExp.$1]) !== undefined) { if ((match = type.match(/^([^\(]+)\(([^,]+),([^\)]+)\)$/)) && (v = validators[match[1]]) !== undefined) {
return function() { return function() {
return v(RegExp.$2, RegExp.$3); return v.apply(this, [match[2], match[3]]);
} }
} else if (type.match(/^([^\(]+)\(([^,\)]+)\)$/) && (v = validators[RegExp.$1]) !== undefined) { } else if ((match = type.match(/^([^\(]+)\(([^,\)]+)\)$/)) && (v = validators[match[1]]) !== undefined) {
return function() { return function() {
return v(RegExp.$2); return v.apply(this, [match[2]]);
} }
} else { } else {
return validators[type]; return validators[type];