Search code examples
phppreg-matchprestashop

Prestashop preg_match cleanNonUnicodeSupport


This is a piece of code of prestashop classes/validate.php:

  public static function isReference($reference)
    {
        return preg_match(Tools::cleanNonUnicodeSupport('/^[^<>;={}]*$/u'), $reference);

This will check it the value is reference or not. Which way does it work, shall there between ' ' quotes be the characters which ARE allowed to go through or the characters which are NOT allowed through? When I left it empty '', nothing went through, but I need to allow anything through.

How to modify this so the reference could be anything?


Solution

  • To be sure to match anything, you can use [\s\S]:

    preg_match(Tools::cleanNonUnicodeSupport('/^[\s\S]*$/u'), $reference);
    

    this will match 0 or more any character.
    or

    preg_match(Tools::cleanNonUnicodeSupport('/^[\s\S]+$/u'), $reference);
    

    this will match 1 or more any character.