[php-src] Issue #14306: Preg unicode different results depending on if in character class or separate

From: Date: Thu, 23 May 2024 15:41:57 +0000
Subject: [php-src] Issue #14306: Preg unicode different results depending on if in character class or separate
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246952@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/14306 Author: kkmuffme ### Description The following code: https://3v4l.org/7O4RL ```php <?php $message = 'a–b'; var_dump(preg_match('/a[–]b/', $message, $match)); var_dump($match); var_dump(preg_match('/a[–]b/u', $message, $match)); var_dump($match); var_dump(preg_match('/a–b/', $message, $match)); var_dump($match); $message = 'a💩b'; var_dump(preg_match('/a[💩]b/', $message, $match)); var_dump($match); var_dump(preg_match('/a[💩]b/u', $message, $match)); var_dump($match); var_dump(preg_match('/a💩b/', $message, $match)); var_dump($match); ``` Resulted in this output: ``` int(0) array(0) { } int(1) array(1) { [0]=> string(5) "a–b" } int(1) array(1) { [0]=> string(5) "a–b" } int(0) array(0) { } int(1) array(1) { [0]=> string(6) "a💩b" } int(1) array(1) { [0]=> string(6) "a💩b" } ``` But I expected this output instead: ``` int(1) array(1) { [0]=> string(5) "a–b" } int(1) array(1) { [0]=> string(5) "a–b" } int(1) array(1) { [0]=> string(5) "a–b" } int(1) array(1) { [0]=> string(6) "a💩b" } int(1) array(1) { [0]=> string(6) "a💩b" } int(1) array(1) { [0]=> string(6) "a💩b" } ``` Why are unicode characters treated differently if they're in a character class? ### PHP Version PHP 8.3.7 ### Operating System _No response_

« previous php.bugs (#246952) next »