|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74264 grapheme_sttrpos() broken for negative offsets
Submitted: 2017-03-17 15:42 UTC Modified: 2021-06-23 13:43 UTC
From: webmaster at apprendre-php dot com Assigned: cmb (profile)
Status: Closed Package: intl (PECL)
PHP Version: 5.6.30 OS: Mac OS X Yosemite 10.10.5
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: webmaster at apprendre-php dot com
New email:
PHP Version: OS:


 [2017-03-17 15:42 UTC] webmaster at apprendre-php dot com

I'm currently working on a group of classes abstracting operations on ASCII and UTF8 strings using either the native string functions or multibytes functions or graphemes cluster functions from intl extension.

It seems the grapheme_strripos() and grapheme_strrpos() functions don't calculate a position right when they receive an accentuated string AND a negative offset. However the position calculus is correct when these functions receive an accentuated string AND a positive offset.

If you look at the attached piece of test script, the statements #5 and #6 are expected to return int(5) but they return int(6) instead. If you try this behavior with mb_strrpos() and mb_strripos() functions instead, the output will be int(5) as expected.

You can find the tested scenario here:

Test script:
// Expecting int(6) [3 times]
var_dump(grapheme_strrpos('dejaaaa', 'a', 2));   // int(6)
var_dump(grapheme_strrpos('déjàààà', 'à', 2));   // int(6)
var_dump(grapheme_strripos('DÉJÀÀÀÀ', 'à', 2));  // int(6)

// Expecting int(5) [3 times]
var_dump(grapheme_strrpos('dejaaaa', 'a', -2));  // int(5)
var_dump(grapheme_strrpos('déjàààà', 'à', -2));  // int(6)
var_dump(grapheme_strripos('DÉJÀÀÀÀ', 'à', -2)); // int(6)

// Expecting int(5) [3 times]
var_dump(mb_strrpos('dejaaaa', 'a', -2));        // int(5)
var_dump(mb_strrpos('déjàààà', 'à', -2));        // int(5)
var_dump(mb_strripos('DÉJÀÀÀÀ', 'à', -2));       // int(5)


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-06-23 13:43 UTC]
-Summary: Wrong position with grapheme_strr*pos() functions and negative offsets +Summary: grapheme_sttrpos() broken for negative offsets -Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2021-06-23 13:43 UTC]
Apparently, this has been overlooked when negative offsets have
been introduced for these functions.
 [2021-06-23 13:50 UTC]
The following pull request has been associated:

Patch Name: Fix #74264: grapheme_sttrpos() broken for negative offsets
On GitHub:
 [2021-07-05 16:23 UTC]
Automatic comment on behalf of cmb69
Log: Fix #74264: grapheme_strrpos() broken for negative offsets
 [2021-07-05 16:23 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Sep 24 20:01:25 2023 UTC