Bug #77334 [NEW]: Issue with preg_replace shorthand character in character class
| From: | webdev at westernseminary dot edu | Date: | Fri, 21 Dec 2018 16:58:01 +0000 |
| Subject: | Bug #77334 [NEW]: Issue with preg_replace shorthand character in character class | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-218552@lists.php.net to get a copy of this message | ||
From: webdev at westernseminary dot edu
Operating system: Windows Server 2012
PHP version: 7.3.0
Package: *Regular Expressions
Bug Type: Bug
Bug description:Issue with preg_replace shorthand character in character class
Description:
------------
When a shorthand character (\d) is used in a character class ([\d])
along wiht a dash and a dot, the regular expression throws an error in
PHP 7.3.0 even though the regular expression is valid. The error does
not occur in PHP 7.2.13.
Test script:
---------------
// SHORT EXAMPLE
echo preg_replace('/[^\d-\.]/', '', '123abc');
// LONG EXAMPLE
$value = '123abc';
$rgxs = array(
'/[\d]/',
'/[\d-]/',
'/[\d\.]/',
'/[\d-\.]/', //bug
'/[\d\.-]/',
'/[^\d]/',
'/[^\d-]/',
'/[^\d\.]/',
'/[^\d-\.]/', //bug
'/[^\w-\.]/', //bug
'/[^0-9-\.]/',
);
echo '<table border="1" cellpadding="10">';
echo '<tr>';
echo '<th>Index</th>';
echo '<th>Regular Expression</th>';
echo '<th>Result</th>';
echo '<th>Last Error</th>';
echo '</tr>';
foreach($rgxs as $i => $rgx) {
echo '<tr>';
echo '<td>'.$i.'</td>';
echo '<td>'.$rgx.'</td>';
echo '<td>'.preg_replace($rgx, '', $value).'</td>';
echo '<td>'.preg_last_error().'</td>';
echo '</tr>';
}
echo '</table>';
Expected result:
----------------
For the short example, the expected result would be "123".
Actual result:
--------------
For the short example, the actual result is NULL.
--
Edit bug report at https://bugs.php.net/bug.php?id=77334&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77334&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77334&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77334&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77334&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77334&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77334&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77334&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77334&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77334&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77334&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77334&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77334&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77334&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77334&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77334&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77334&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77334&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77334&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77334&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77334&r=mysqlcfg