Browse Source

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.
Matthias Schiffer 7 years ago
parent
commit
da19961188

File diff suppressed because it is too large
+ 0 - 0
package/gluon-web/files/lib/gluon/web/www/static/resources/gluon-web.js


+ 11 - 10
package/gluon-web/javascript/gluon-web.js

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

Some files were not shown because too many files changed in this diff