Bug #69144 [Opn->Csd]: strtr not replacing with partly matching replace pairs
| From: | laruence@php.net | Date: | Sat, 28 Feb 2015 14:38:10 +0000 |
| Subject: | Bug #69144 [Opn->Csd]: strtr not replacing with partly matching replace pairs | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-191008@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69144&edit=1
ID: 69144
Updated by: laruence@php.net
Reported by: wouter at wouterj dot nl
Summary: strtr not replacing with partly matching replace
pairs
-Status: Open
+Status: Closed
Type: Bug
Package: Strings related
PHP Version: master-Git-2015-02-28 (snap)
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=54e2020ee3e6142a86db03f1a9d47bc763334dbb
Log: Fixed bug #69144 (strtr not replacing with partly matching replace pairs)
Previous Comments:
------------------------------------------------------------------------
[2015-02-28 11:15:33] wouter at wouterj dot nl
Description:
------------
Testing against the latest PHP 7 version, there seem to be a bug with the strtr function. As soon as
you use replace pairs (the 2 arguments usage), the function won't replace anything if the
replace pairs are matching eachother (e.g. in the test script "foobar" matches both
"fo" and "bar").
From some tests[1], it seems like this bug has been introduced between January 1st and February 1st
in the PHP 7 branch.
[1] http://3v4l.org/FTV2L
Test script:
---------------
<?php
$tests = array('bar' => '', 'foo' => 'o',
'foobar' => '', 'hello' => 'hello');
foreach ($tests as $input => $expected) {
if ($expected !== ($actual = strtr($input, array("fo" => "",
"foobar" => "", "bar" => "")))) {
echo "KO
$input became $actual instead of
$expected\n";
} else {
echo "OK $input became $expected\n";
}
}
?>
Expected result:
----------------
OK bar became ``
OK foo became o
OK foobar became ``
OK hello became hello
Actual result:
--------------
KO bar became bar instead of ``
KO foo became foo instead of o
KO foobar became foobar instead of ``
OK hello became hello
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69144&edit=1