php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42678 reg_replace returns empty string on certain data
Submitted: 2007-09-15 19:15 UTC Modified: 2007-09-15 19:31 UTC
From: jana dot vasseru at gmail dot com Assigned:
Status: Not a bug Package: *Regular Expressions
PHP Version: 5.2.4 OS: W2000
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jana dot vasseru at gmail dot com
New email:
PHP Version: OS:

 

 [2007-09-15 19:15 UTC] jana dot vasseru at gmail dot com
Description:
------------
On certain data preg_replace() returns empty string. The code below works correctly on PHP 5.1.6

Reproduce code:
---------------
<?php

$data = file_get_contents('src.sql');
echo strlen($data).'<br>';
$data = preg_replace("#INSERT\\sINTO([\\s\\S]*?)INSERT\\sINTO#", "\$DELTA_SCRIPT[] = 'INSERT INTO\\1'; \$DELTA_SCRIPT[] = 'INSERT INTO", $data);
$data = preg_replace("#CREATE\\sTABLE([\\s\\S]*?)[^']INSERT\\sINTO#", "CREATE TABLE \\1 \$DELTA_SCRIPT[] = 'INSERT INTO", $data);
echo strlen($data); //returns 0 here

?>

Expected result:
----------------
Return whatever but empty string.

Actual result:
--------------
Returns empty string.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-15 19:17 UTC] jana dot vasseru at gmail dot com
The exact text file triggering the error can be found here:
http://virklis.cust.ignum.cz/src.sql
163 337 byte
 [2007-09-15 19:31 UTC] scottmac@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Check preg_last_error() you've probably hit one of the limits to stop you smashing the stack.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Dec 07 10:03:34 2021 UTC