Skip to content

Commit

Permalink
Fixing a nasty parser bug (#103). The negative look ahead was hogging…
Browse files Browse the repository at this point in the history
… memory in lists with large contents. The new regex should handle this better.

The problem was both found and fixed by ridgerunner, so a big thanks! More information can be found at http://jmrware.com/articles/2009/fluxbb/FluxParserRegexes.html
  • Loading branch information
reines committed Jan 8, 2010
1 parent 2619819 commit a62da4b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions upload/include/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function preparse_bbcode($text, &$errors, $is_signature = false)
}

// Tidy up lists
$pattern = array('%\[list(?:=([1a*]))?+\]((?:(?:(?!\[list(?:=[1a*])?+\]|\[/list\]).)++|(?R))*+)\[/list\]%isxe');
$pattern = array('%\[list(?:=([1a*]))?+\]((?:(?>.*?(?=\[list(?:=[1a*])?+\]|\[/list\]))|(?R))*)\[/list\]%ise');
$replace = array('preparse_list_tag(\'$2\', \'$1\', $errors)');
$text = preg_replace($pattern, $replace, $text);

Expand Down Expand Up @@ -516,7 +516,7 @@ function preparse_list_tag($content, $type = '*', &$errors)

if (strpos($content,'[list') !== false)
{
$pattern = array('%\[list(?:=([1a*]))?+\]((?:(?:(?!\[list(?:=[1a*])?+\]|\[/list\]).)++|(?R))*+)\[/list\]%isxe');
$pattern = array('%\[list(?:=([1a*]))?+\]((?:(?>.*?(?=\[list(?:=[1a*])?+\]|\[/list\]))|(?R))*)\[/list\]%ise');
$replace = array('preparse_list_tag(\'$2\', \'$1\', $errors)');
$content = preg_replace($pattern, $replace, $content);
}
Expand Down Expand Up @@ -646,7 +646,7 @@ function handle_list_tag($content, $type = '*')

if (strpos($content,'[list') !== false)
{
$pattern = array('%\[list(?:=([1a*]))?+\]((?:(?:(?!\[list(?:=[1a*])?+\]|\[/list\]).)++|(?R))*+)\[/list\]%isxe');
$pattern = array('%\[list(?:=([1a*]))?+\]((?:(?>.*?(?=\[list(?:=[1a*])?+\]|\[/list\]))|(?R))*)\[/list\]%ise');
$replace = array('handle_list_tag(\'$2\', \'$1\')');
$content = preg_replace($pattern, $replace, $content);
}
Expand Down Expand Up @@ -685,7 +685,7 @@ function do_bbcode($text, $is_signature = false)

if (!$is_signature)
{
$pattern[] = '%\[list(?:=([1a*]))?+\]((?:(?:(?!\[list(?:=[1a*])?+\]|\[/list\]).)++|(?R))*+)\[/list\]%isxe';
$pattern[] = '%\[list(?:=([1a*]))?+\]((?:(?>.*?(?=\[list(?:=[1a*])?+\]|\[/list\]))|(?R))*)\[/list\]%ise';
$replace[] = 'handle_list_tag(\'$2\', \'$1\')';
}

Expand Down

0 comments on commit a62da4b

Please sign in to comment.