fix(regex): add missing 4th octet to email address IPv4 domain preset

The 'Email address' preset in the Regular Expression operation was
missing the 4th IPv4 octet in the bracketed address form, causing
addresses like user@[1.2.3.4] to never match.

The IPv4 bracket group ended after {3} repetitions of 'octet.':
  \\[(?:(?:(octet))\.){3}\\]

This matches [1.2.3.] (a false positive) but not [1.2.3.4].

Fix: add the 4th octet group before the closing bracket, mirroring
the correct regex already used in ExtractEmailAddresses.mjs:
  \\[(?:(?:(octet))\.){3}(?:(octet))\\]

Closes #2150
This commit is contained in:
terminalchai 2026-04-12 02:42:30 +05:30
parent 4deaa0de20
commit a3f4e15b29
2 changed files with 13 additions and 2 deletions

View File

@ -45,7 +45,7 @@ class RegularExpression extends Operation {
},
{
name: "Email address",
value: "(?:[\\u00A0-\\uD7FF\\uE000-\\uFFFFa-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\u00A0-\\uD7FF\\uE000-\\uFFFFa-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[\\u00A0-\\uD7FF\\uE000-\\uFFFFa-z0-9](?:[\\u00A0-\\uD7FF\\uE000-\\uFFFF-a-z0-9-]*[\\u00A0-\\uD7FF\\uE000-\\uFFFFa-z0-9])?\\.)+[\\u00A0-\\uD7FF\\uE000-\\uFFFFa-z0-9](?:[\\u00A0-\\uD7FF\\uE000-\\uFFFFa-z0-9-]*[\\u00A0-\\uD7FF\\uE000-\\uFFFFa-z0-9])?|\\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\.){3}\\])"
value: "(?:[\\u00A0-\\uD7FF\\uE000-\\uFFFFa-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\u00A0-\\uD7FF\\uE000-\\uFFFFa-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[\\u00A0-\\uD7FF\\uE000-\\uFFFFa-z0-9](?:[\\u00A0-\\uD7FF\\uE000-\\uFFFF-a-z0-9-]*[\\u00A0-\\uD7FF\\uE000-\\uFFFFa-z0-9])?\\.)+[\\u00A0-\\uD7FF\\uE000-\\uFFFFa-z0-9](?:[\\u00A0-\\uD7FF\\uE000-\\uFFFFa-z0-9-]*[\\u00A0-\\uD7FF\\uE000-\\uFFFFa-z0-9])?|\\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\])"
},
{
name: "URL",

View File

@ -55,5 +55,16 @@ TestRegister.addTests([
"args": ["User defined", "\\pS", true, true, false, false, true, false, "List matches"]
}
],
}
},
{
name: "Regex: Email address preset matches IPv4 domain",
input: "user@[1.2.3.4]\ntest@[192.168.0.1]\nno-match@[1.2.3.]",
expectedOutput: "user@[1.2.3.4]\ntest@[192.168.0.1]",
recipeConfig: [
{
"op": "Regular expression",
"args": ["Email address", "", true, true, false, false, false, false, "List matches"]
}
],
},
]);