summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/htdocs/luci-static/resources/validation.js
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2020-05-17 21:34:30 +0200
committerJo-Philipp Wich <jo@mein.io>2020-05-17 21:40:27 +0200
commit9a41673488dd7725c8a7f69430b5c8559a038695 (patch)
tree3eeff9ada78a23ea7f4ef5744f20a94a01011d5c /modules/luci-base/htdocs/luci-static/resources/validation.js
parent01d5d5f92963d9596a3c0b669a7e8d87b64132d5 (diff)
luci-base: validation.js: count byte- instead of character length of strings
Fixes: #4055 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/htdocs/luci-static/resources/validation.js')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/validation.js15
1 files changed, 9 insertions, 6 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/validation.js b/modules/luci-base/htdocs/luci-static/resources/validation.js
index eea837d64e..769d2a9553 100644
--- a/modules/luci-base/htdocs/luci-static/resources/validation.js
+++ b/modules/luci-base/htdocs/luci-static/resources/validation.js
@@ -1,6 +1,10 @@
'use strict';
'require baseclass';
+function bytelen(x) {
+ return new Blob([x]).size;
+}
+
var Validator = baseclass.extend({
__name__: 'Validation',
@@ -421,24 +425,23 @@ var ValidatorFactory = baseclass.extend({
},
length: function(len) {
- var val = '' + this.value;
- return this.assert(val.length == +len,
+ return this.assert(bytelen(this.value) == +len,
_('value with %d characters').format(len));
},
rangelength: function(min, max) {
- var val = '' + this.value;
- return this.assert((val.length >= +min) && (val.length <= +max),
+ var len = bytelen(this.value);
+ return this.assert((len >= +min) && (len <= +max),
_('value between %d and %d characters').format(min, max));
},
minlength: function(min) {
- return this.assert((''+this.value).length >= +min,
+ return this.assert(bytelen(this.value) >= +min,
_('value with at least %d characters').format(min));
},
maxlength: function(max) {
- return this.assert((''+this.value).length <= +max,
+ return this.assert(bytelen(this.value) <= +max,
_('value with at most %d characters').format(max));
},