Wixel / GUMP

A fast, extensible & stand-alone PHP input validation class that allows you to validate any data
https://wixelhq.com
MIT License
1.17k stars 341 forks source link

Regex Crashes GUMP #307

Closed netz0 closed 4 years ago

netz0 commented 4 years ago

It seems there is something wrong in how GUMP handles regex validations. I have tried every possible hostname/FQDN regex combination and GUMP will trow a PHP error on all tests.

Same regex matches work fine while using straight PHP preg_match pattern without GUMP.

Example of regex that will break GUMP: 'host' => 'regex,/^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$/', // Validate hostname RFC 1123

Will fail with: Warning: preg_match(): No ending delimiter '/' found in gump.class.php on line 2160

Fatal error: Uncaught Exception: Validator method 'validate_[a-zA-Z][a-zA-Z0-9-][a-zA-Z0-9]).)([A-Za-z]' does not exist / in gump.class.php:456

Simple regex functions work. The second you try something a bit more complex and it fails with the same error.

netz0 commented 4 years ago

It seems this is related to some fix with brackets on arrays, except since you removed the examples starting on version 1.6 its impossible to see how the new array format works. Why was the example folder removed? The README does not replace real code examples.

filisko commented 4 years ago

I can see a pipe on your regex. |

There is a note in readme saying this.

If you use Pipe or Semicolon as parameter value, you must use array format.

$is_valid = GUMP::is_valid(array_merge($_POST, $_FILES), [
    'field' => 'regex,/partOf;my|Regex/', // NO
    'field' => ['regex' => '/partOf;my|Regex/'] // YES
]);

https://github.com/Wixel/GUMP/blob/master/README.md#star-available-validators

And yes, old examples where replaced by new ones so everyone starts with the "good way" of doing it.

its impossible to see how the new array format works.

not true, there are multiple examples on docs.