php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: webmaster at apprendre-php dot com
New email:
PHP Version: OS:

 

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

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: https://3v4l.org/UmN6B

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)


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-06-23 13:43 UTC] cmb@php.net
-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] cmb@php.net
Apparently, this has been overlooked when negative offsets have
been introduced for these functions.
 [2021-06-23 13:50 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #74264: grapheme_sttrpos() broken for negative offsets
On GitHub:  https://github.com/php/php-src/pull/7189
Patch:      https://github.com/php/php-src/pull/7189.patch
 [2021-07-05 16:23 UTC] git@php.net
Automatic comment on behalf of cmb69
Revision: https://github.com/php/php-src/commit/28c93763069c5b184b81a153cb135ccd18f62d14
Log: Fix #74264: grapheme_strrpos() broken for negative offsets
 [2021-07-05 16:23 UTC] git@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC