Bug #80166 [NEW]: preg_match_all()'s PREG_OFFSET_CAPTURE ignoring modifier u
| From: | thomas at landauer dot at | Date: | Thu, 01 Oct 2020 12:02:18 +0000 |
| Subject: | Bug #80166 [NEW]: preg_match_all()'s PREG_OFFSET_CAPTURE ignoring modifier u | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-229301@lists.php.net to get a copy of this message | ||
From: thomas at landauer dot at
Operating system: Linux
PHP version: 7.2.33
Package: PCRE related
Bug Type: Bug
Bug description:preg_match_all()'s PREG_OFFSET_CAPTURE ignoring modifier u
Description:
------------
PREG_OFFSET_CAPTURE always counts utf-8 special characters as *2*
(bytes) - no matter if the modifier
u (PCRE_UTF8) is present or not.
This has been reported before at https://bugs.php.net/bug.php?id=37391
but got closed as "Not a bug". However, taking a look at the
documentation clearly shows that this *is* a bug:
https://www.php.net/manual/en/function.preg-match-all.php#refsect1-function.preg-match-all-parameters
says about PREG_OFFSET_CAPTURE
> If this flag is passed, for every occurring match the appendant string
offset will also be returned.
"string offset" obviously refers to the number of *characters* in front
of the match.
And https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php
says about u (PCRE_UTF8):
> Pattern and subject strings are treated as UTF-8.
My actual PHP version is 7.2.24
Test script:
---------------
preg_match_all('/a/u', 'öa', $matches, PREG_OFFSET_CAPTURE);
var_dump($matches);
Expected result:
----------------
[1]=>int(1)
Actual result:
--------------
[1]=>int(2)
(=expected result without modifier u)
--
Edit bug report at https://bugs.php.net/bug.php?id=80166&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80166&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80166&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80166&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80166&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80166&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80166&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80166&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80166&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80166&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80166&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80166&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80166&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80166&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80166&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80166&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80166&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80166&r=mysqlcfg