preg_replace bug

Problems with the Windows version of XAMPP, questions, comments, and anything related.

preg_replace bug

Postby shannah » 30. March 2011 04:07

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
shannah
 
Posts: 1
Joined: 30. March 2011 03:59

Re: preg_replace bug

Postby Sharley » 30. March 2011 05:17

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.
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: preg_replace bug

Postby Altrea » 30. March 2011 06:46

successfully tested without error on Zend Server CE (PHP 5.3.5) | Windows XP 32Bit
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: preg_replace bug

Postby pateld » 31. August 2011 18:08

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.
pateld
 
Posts: 1
Joined: 31. August 2011 18:02


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 92 guests