diff options
author | Sébastien Kergreis <seb.kerro@gmail.com> | 2016-05-31 15:44:09 -0500 |
---|---|---|
committer | Sébastien Kergreis <seb.kerro@gmail.com> | 2016-06-01 13:48:22 -0500 |
commit | 6af3b6dfdbd2be9de3a3d670b89f694e4fcffd69 (patch) | |
tree | b429602abc74d217b42b2367aba7426b29bcc9e5 /app/Core | |
parent | 4987e245bb629e3171425bf16db341c5c3a7c3c7 (diff) |
Fix filters with UTF-8 characters
Diffstat (limited to 'app/Core')
-rw-r--r-- | app/Core/Filter/Lexer.php | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/app/Core/Filter/Lexer.php b/app/Core/Filter/Lexer.php index 8a7a68b1..fa5b8d2d 100644 --- a/app/Core/Filter/Lexer.php +++ b/app/Core/Filter/Lexer.php @@ -25,13 +25,13 @@ class Lexer * @var array */ private $tokenMap = array( - "/^(\s+)/" => 'T_WHITESPACE', + '/^(\s+)/' => 'T_WHITESPACE', '/^([<=>]{0,2}[0-9]{4}-[0-9]{2}-[0-9]{2})/' => 'T_STRING', - '/^([<=>]{1,2}\w+)/' => 'T_STRING', + '/^([<=>]{1,2}\w+)/u' => 'T_STRING', '/^([<=>]{1,2}".+")/' => 'T_STRING', '/^("(.+)")/' => 'T_STRING', - "/^(\w+)/" => 'T_STRING', - "/^(#\d+)/" => 'T_STRING', + '/^(\w+)/u' => 'T_STRING', + '/^(#\d+)/' => 'T_STRING', ); /** @@ -80,9 +80,10 @@ class Lexer { $tokens = array(); $this->offset = 0; + $input_length = mb_strlen($input, 'UTF-8'); - while (isset($input[$this->offset])) { - $result = $this->match(substr($input, $this->offset)); + while ($this->offset < $input_length) { + $result = $this->match(mb_substr($input, $this->offset, $input_length, 'UTF-8')); if ($result === false) { return array(); @@ -105,7 +106,7 @@ class Lexer { foreach ($this->tokenMap as $pattern => $name) { if (preg_match($pattern, $string, $matches)) { - $this->offset += strlen($matches[1]); + $this->offset += mb_strlen($matches[1], 'UTF-8'); return array( 'match' => str_replace('"', '', $matches[1]), |