* [pmg-devel] [PATCH pmg-gui] utils: escape `/` in regex for emails
@ 2023-11-30 12:44 Maximiliano Sandoval
2024-02-23 18:11 ` Stoiko Ivanov
0 siblings, 1 reply; 4+ messages in thread
From: Maximiliano Sandoval @ 2023-11-30 12:44 UTC (permalink / raw)
To: pmg-devel
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@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@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@example.com",
});
--
2.39.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pmg-devel] [PATCH pmg-gui] utils: escape `/` in regex for emails
2023-11-30 12:44 [pmg-devel] [PATCH pmg-gui] utils: escape `/` in regex for emails Maximiliano Sandoval
@ 2024-02-23 18:11 ` Stoiko Ivanov
2024-02-26 7:07 ` Dominik Csapak
0 siblings, 1 reply; 4+ messages in thread
From: Stoiko Ivanov @ 2024-02-23 18:11 UTC (permalink / raw)
To: Maximiliano Sandoval; +Cc: pmg-devel
Thomas and I talked shortly off-list - and I remembered that we
(Maximiliano and I) - also talked off-list quite a while ago...
sadly I forgot if we agreed on a v2, or if the issue was more with gettext?
just before this gets forgotten:
On Thu, 30 Nov 2023 13:44:16 +0100
Maximiliano Sandoval <m.sandoval@proxmox.com> wrote:
> 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@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@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);
as is this fails at eslint
from a quick search at developer.mozilla.org:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class:
```
This means /[/]/ is valid without needing to escape the /.
```
also:
```
These are syntax characters in regexes (/ is the delimiter of a regex literal), so they require escaping unless in a character class.
```
(and '/' is in a character-class)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_escape
> },
> PMGMailText: gettext('Example') + ": user@example.com",
> });
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pmg-devel] [PATCH pmg-gui] utils: escape `/` in regex for emails
2024-02-23 18:11 ` Stoiko Ivanov
@ 2024-02-26 7:07 ` Dominik Csapak
2024-02-26 12:14 ` Thomas Lamprecht
0 siblings, 1 reply; 4+ messages in thread
From: Dominik Csapak @ 2024-02-26 7:07 UTC (permalink / raw)
To: Stoiko Ivanov, Maximiliano Sandoval; +Cc: pmg-devel
AFAICS the original issue
On 2/23/24 19:11, Stoiko Ivanov wrote:
>>
>> Note that `/` marks the end of the regex [1], hence
>>
>> Some@example@oh\no@
>>
>> is valid according to this regex if we do not escape `/`.
>>
is not because of unescaped '/' but because the regex is not anchored
and thus only parts of the input must match... (and that it does)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pmg-devel] [PATCH pmg-gui] utils: escape `/` in regex for emails
2024-02-26 7:07 ` Dominik Csapak
@ 2024-02-26 12:14 ` Thomas Lamprecht
0 siblings, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2024-02-26 12:14 UTC (permalink / raw)
To: Dominik Csapak, Maximiliano Sandoval; +Cc: pmg-devel, Stoiko Ivanov
Am 26/02/2024 um 08:07 schrieb Dominik Csapak:
> On 2/23/24 19:11, Stoiko Ivanov wrote:
>
FYI: this makes it seem like below was written by Stoiko, but it wasn't,
it's rather part of Maximiliano's original commit message.
>>>
>>> Note that `/` marks the end of the regex [1], hence
>>>
>>> Some@example@oh\no@
>>>
>>> is valid according to this regex if we do not escape `/`.
>>>
>
> is not because of unescaped '/' but because the regex is not anchored
> and thus only parts of the input must match... (and that it does)
>
yeah, that seems indeed to be the issue. @Maximiliano can you please try that
and send a patch for it, if it works out.
And FWIW, the extra parenthesis around the regex could be dropped too (just
a code style improvement though), so
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-02-26 12:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-30 12:44 [pmg-devel] [PATCH pmg-gui] utils: escape `/` in regex for emails Maximiliano Sandoval
2024-02-23 18:11 ` Stoiko Ivanov
2024-02-26 7:07 ` Dominik Csapak
2024-02-26 12:14 ` Thomas Lamprecht
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox