From 181747d006cb105ed31aa82010563562b95eb265 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sat, 10 Mar 2018 17:53:41 +0100 Subject: [PATCH] Fix not working textbox validators containing backslashes PHP xml parser reads backslashes literal from attributes, while JavaScript ones need them escaped (eg. like PHP strings) -> replace \\ with \ to get following XML working: validator="/^\\d+$" --- api/src/Etemplate/Widget/Textbox.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/src/Etemplate/Widget/Textbox.php b/api/src/Etemplate/Widget/Textbox.php index 081a2e4d47..de542899f3 100644 --- a/api/src/Etemplate/Widget/Textbox.php +++ b/api/src/Etemplate/Widget/Textbox.php @@ -156,7 +156,9 @@ class Textbox extends Etemplate\Widget { $value = mb_substr($value,0,(int) $this->attrs['maxlength']); } - if ($this->attrs['validator'] && !preg_match($this->attrs['validator'],$value)) + // PHP xml parser reads backslashes literal from attributes, while JavaScript ones need them escaped (eg. like PHP strings) + // --> replace \\ with \ to get following XML working: validator="/^\\d+$" (server- AND client-side!) + if ($this->attrs['validator'] && !preg_match(str_replace('\\\\','\\', $this->attrs['validator']), $value)) { switch($this->attrs['type']) {