[Plugin: Cimy User Extra Fields][Bug?][Patch incl]Case sensitive versus regex
-
Hi Marco,
I’ve run into another little issue. This one I think can be solved quickly and easily.
When an admin adds regex validation to a cimy field and does not check the ‘case-sensitive’ option, the regex is still run as if it was case-sensitive.
For example:
Say you have a regex/^[a-z0-9_]{1,16}$/(Twitter username validation) and you have not checked the “Case sensitive” checkbox.
If a user enters ‘MyUsername’, the validation will reject it.I know I can change the regex to be case-insensitive (which I have for now), but I would find it more intuitive for the case-sensitive option to be respected – even when using a regex -.
The patch would be quite simple. The only place in the code where I found a preg_match is in cimy_uef_register.php.
Original code line 450-455:
if ($rules['equal_to_regex']) { if (!preg_match($equalTo, $value)) { $equalmsg = " ".__("isnβt correct", $cimy_uef_domain); $errors->add($unique_id, '<strong>'.__("ERROR", $cimy_uef_domain).'</strong>: '.$label.$equalmsg.'.'); } }If you change those lines to the following, I believe it will be patched (one extra line after the first if):
if ($rules['equal_to_regex']) { $equalTo = ( ( !$rules['equal_to_case_sensitive'] ) ? $equalTo . 'iu' : $equalTo . 'u' ); if (!preg_match($equalTo, $value)) { $equalmsg = " ".__("isnβt correct", $cimy_uef_domain); $errors->add($unique_id, '<strong>'.__("ERROR", $cimy_uef_domain).'</strong>: '.$label.$equalmsg.'.'); } }I also added the -u modifier at the end so that preg_match() will deal with utf-8 strings in the pattern correctly.
Ref: PHP Manual PRCE pattern modifiers.I hope this helps!
Keep up the good work π
Smile,
Juliette
The topic ‘[Plugin: Cimy User Extra Fields][Bug?][Patch incl]Case sensitive versus regex’ is closed to new replies.