Page 1 of 1

preg_replace bug

PostPosted: 30. March 2011 04:07
by shannah
The latest beta version of XAMPP (1.7.5-beta 1) appears to have a bug with preg_replace. As I don't have any other PHP 5.3.5 installs running right now I don't know whether the problem is a PHP bug, a regex library bug, or a problem with the XAMP build.

I am running XAMP 1.7.5-beta 1 on Windows 7.

Below is a minimal script to produce the error. If you run this script it will produce a segmentation fault and Apache will crash.

[code]
<?php
$html = <<<END
<tr id="copy-replace-field-product_name-row" style="display: none">
<td id="copy-replace-field-product_name-label-cell" class="copy-replace-field-label-cell" valign="top" align="right">
<label>Product name</label>
</td>
<td id="copy-replace-field-product_name-widget-cell" class="copy-replace-field-widget-cell" valign="top" align="left">
<!-- BEGIN required --><span style="color: #ff0000" class="fieldRequired" title="required">&nbsp;</span><!-- END required -->
<!-- BEGIN error --><div class="fieldError" style="color: #ff0000">{error}</div><!-- END error -->
{element}
(<input type="checkbox" name="-copy_replace:blank_flag[product_name]" label="Leave Blank"><label for="-copy_replace:blank_flag[product_name]">Make Blank</label>)
</td>
</tr>
END;
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->(\s|\S)*<!-- END required -->([ \t\n\r]*)?/i", '', $html);
echo "success";
[code]

I haven't had a chance to narrow it down too much further, but I do know the following:

1. Works fine running on PHP 5.3.2, 5.2.8, 5.2.6, and 5.1 on other setups.
2. This will work if you change the regex from
"/([ \t\n\r]*)?<!-- BEGIN required -->(\s|\S)*<!-- END required -->([ \t\n\r]*)?/i"
to
"/([ \t\n\r]*)?<!-- BEGIN required -->.*?<!-- END required -->([ \t\n\r]*)?/i"

If anyone has PHP 5.3.5 running on something other than XAMPP can you try this test and see if it fails?

-Steve

Re: preg_replace bug

PostPosted: 30. March 2011 05:17
by Sharley
Sorry Steve, I can't test it for you but please do tell the developers about this issue by filling in the form on the beta page:
http://www.apachefriends.org/en/xampp-beta.html
The form has a direct connection to the Windows XAMPP developers and if you include an email address then they should respond and be able to test this at the coal face, so to speak.

The developers don't frequent these forums very much so the chances of them seeing your post are pretty slim.

Good luck and best wishes.

Re: preg_replace bug

PostPosted: 30. March 2011 06:46
by Altrea
successfully tested without error on Zend Server CE (PHP 5.3.5) | Windows XP 32Bit

Re: preg_replace bug

PostPosted: 31. August 2011 18:08
by pateld
I have the same issue and found the problem. It is related to Apache stack size on Windows. I have Apache 2.2.19 and PHP 5.3.8 on Windows 7 64bit and still issue persist.

What you can do to make it run on Windows box is, use lesser arguments in preg_replace(...) function. I know that its not optimal solution but that's the only workaround I found.

So for you code,
Code: Select all
$html = <<<END
<tr id="copy-replace-field-product_name-row" style="display: none">
<td id="copy-replace-field-product_name-label-cell" class="copy-replace-field-label-cell" valign="top" align="right">
<label>Product name</label>
</td>
<td id="copy-replace-field-product_name-widget-cell" class="copy-replace-field-widget-cell" valign="top" align="left">
<!-- BEGIN required --><span style="color: #ff0000" class="fieldRequired" title="required">&nbsp;</span><!-- END required -->
<!-- BEGIN error --><div class="fieldError" style="color: #ff0000">{error}</div><!-- END error -->
{element}
(<input type="checkbox" name="-copy_replace:blank_flag[product_name]" label="Leave Blank"><label for="-copy_replace:blank_flag[product_name]">Make Blank</label>)
</td>
</tr>
END;
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->(\s|\S)*<!-- END required -->([ \t\n\r]*)?/i", '', $html);
echo "success";


Replace,
Code: Select all
$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->(\s|\S)*<!-- END required -->([ \t\n\r]*)?/i", '', $html);


with
Code: Select all
$html = preg_replace("/<!-- BEGIN required -->.*?<!-- END required -->/i", '', $input);


It will work the way you want to be. It should fix the apache problem and produce desired result.

I know your code is from Xataface and I am currently working on that as well.