From 38c9ed00ed8ca70e5c032e2f6ecc6eb59aaafc5e Mon Sep 17 00:00:00 2001 From: Elliott Eggleston Date: Mon, 5 Nov 2018 14:54:55 -0500 Subject: [PATCH] Fix misplaced hyphens in regex Inside a character range surrounded by [], the hyphen is interpreted as defining a range, unless it's the first character. Move the hyphens to the first character in the square brackets where it's supposed to be interpreted as a hyphen. Under PHP 7.3, the previous code failed with error message preg_match(): Compilation failed: invalid range in character class at offset 7 --- CRM/Utils/Rule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Utils/Rule.php b/CRM/Utils/Rule.php index ee5661d4f3..9b45124d25 100644 --- a/CRM/Utils/Rule.php +++ b/CRM/Utils/Rule.php @@ -108,7 +108,7 @@ class CRM_Utils_Rule { // * Composed of alphanumeric chars, underscore and hyphens. // * Maximum length of 64 chars. // * Optionally surrounded by backticks, in which case spaces also OK. - if (!preg_match('/^((`[\w- ]{1,64}`|[\w-]{1,64})\.)?(`[\w- ]{1,64}`|[\w-]{1,64})$/i', $str)) { + if (!preg_match('/^((`[-\w ]{1,64}`|[-\w]{1,64})\.)?(`[-\w ]{1,64}`|[-\w]{1,64})$/i', $str)) { return FALSE; } -- 2.25.1