[pmg-devel] [PATCH pmg-gui] utils: escape `/` in regex for emails

Maximiliano Sandoval m.sandoval at proxmox.com
Thu Nov 30 13:44:16 CET 2023


As it is, it is valid ECMA regex but invalid in many other dialects. We
escape it to make it valid in, say PCRE2.

Note that `/` marks the end of the regex [1], hence

    Some at example@oh\no@

is valid according to this regex if we do not escape `/`.

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_escape

Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
Fun fact: This was detected by xgettext while doing tests extracting
strings for translations.

 js/Utils.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/js/Utils.js b/js/Utils.js
index 7fa154e..8974cb9 100644
--- a/js/Utils.js
+++ b/js/Utils.js
@@ -903,7 +903,7 @@ Ext.define('PMG.Async', {
 Ext.apply(Ext.form.field.VTypes, {
     // matches the pmg-email-address in pmg-api
     PMGMail: function(v) {
-	return (/[^\s\\@]+@[^\s/\\@]+/).test(v);
+	return (/[^\s\\@]+@[^\s\/\\@]+/).test(v);
     },
     PMGMailText: gettext('Example') + ": user at example.com",
 });
-- 
2.39.2





More information about the pmg-devel mailing list