Bug #66121 [Opn->Fbk]: UTF-8 lookbehinds match bytes instead of characters

From: Date: Wed, 20 Nov 2013 03:07:02 +0000
Subject: Bug #66121 [Opn->Fbk]: UTF-8 lookbehinds match bytes instead of characters
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182846@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66121&edit=1

 ID:                 66121
 Updated by:         rasmus@php.net
 Reported by:        danielklein at airpost dot net
 Summary:            UTF-8 lookbehinds match bytes instead of characters
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            PCRE related
 PHP Version:        5.5.6
 Block user comment: N
 Private report:     N

 New Comment:

Please test this using the pcretest command line tool which is part of the PCRE package. If you can
reproduce the issue there too, file the bug with the PCRE project. If you can't, we'll
look into it further here.


Previous Comments:
------------------------------------------------------------------------
[2013-11-20 00:01:31] danielklein at airpost dot net

Description:
------------
The test script appears to check every byte position within the UTF-8 encoded character and
backtrack until a valid starting byte is found, then check it. If you remove the improperly inserted
characters the resulting bytes do encode the original character correctly.

Once it has matched the beginning of the string it should then move ahead by a character, not by a
byte.

Test script:
---------------
<?php
// Sinhala characters
print(preg_replace('/(?<!ක)/u', '*', 'ක') .
"\n"); // Works properly
print(preg_replace('/(?<!ක)/u', '*', 'ම') .
"\n"); // Triggers the bug
// English characters
print(preg_replace('/(?<!k)/u', '*', 'k') . "\n"); //
Works properly
print(preg_replace('/(?<!k)/u', '*', 'm') . "\n"); //
Works properly
?>


Expected result:
----------------
*ක
*ම*
*k
*m*

Actual result:
--------------
*ක
*�*�*�*
*k
*m*


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=66121&edit=1


Thread (11 messages)

« previous php.bugs (#182846) next »