php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62759 Buggy grapheme_substr() on edge case
Submitted: 2012-08-06 16:05 UTC Modified: -
From: okin7 at yahoo dot fr Assigned:
Status: Closed Package: *Languages/Translation
PHP Version: 5.4.5 OS:
Private report: No CVE-ID: None
 [2012-08-06 16:05 UTC] okin7 at yahoo dot fr
Description:
------------
See test script below.

The strangest behavior is the difference between a pure ASCII string and an UTF-8 with chars in the [80-FFFF] range.

The other wrong thing is the difference of behavior between substr() and grapheme_substr(). I think substr's behavior is the good one.

Test script:
---------------
<?php

var_dump(substr('deja', 1, -4));
var_dump(substr('deja', -1, 0));
var_dump(grapheme_substr('deja', 1, -4));
var_dump(grapheme_substr('deja', -1, 0));
var_dump(grapheme_substr('déjà', 1, -4));
var_dump(grapheme_substr('déjà', -1, 0));

?>


Expected result:
----------------
bool(false)
string(0) ""
bool(false)
string(0) ""
bool(false)
string(0) ""


Actual result:
--------------
bool(false)
string(0) ""
bool(false)
string(0) ""
string(5) "éjà"
bool(false)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-24 04:27 UTC] stas@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=php-src.git;a=commit;h=860a5c4b01cd63588ed2eaae76cf0243ca8c3173
Log: Fix bug #62759: Buggy grapheme_substr() on edge case
 [2013-06-24 04:27 UTC] stas@php.net
-Status: Open +Status: Closed
 [2013-06-24 04:27 UTC] stas@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=php-src.git;a=commit;h=860a5c4b01cd63588ed2eaae76cf0243ca8c3173
Log: Fix bug #62759: Buggy grapheme_substr() on edge case
 [2014-10-07 23:18 UTC] stas@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=860a5c4b01cd63588ed2eaae76cf0243ca8c3173
Log: Fix bug #62759: Buggy grapheme_substr() on edge case
 [2014-10-07 23:29 UTC] stas@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=860a5c4b01cd63588ed2eaae76cf0243ca8c3173
Log: Fix bug #62759: Buggy grapheme_substr() on edge case
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC