1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-24 20:13:22 +01:00

Merge pull request #3689 from s9e/ticket/13880-fix-master

[ticket/13880] Merge branch 'fix-3.1' into fix-master
This commit is contained in:
Tristan Darricau 2015-06-29 11:33:20 +02:00
commit e4696318bd
2 changed files with 68 additions and 28 deletions

View File

@ -855,28 +855,6 @@ class bbcode_firstpass extends bbcode
else if (preg_match('#^quote(?:="(.*?)")?$#is', $buffer, $m) && substr($out, -1, 1) == '[')
{
$this->parsed_items['quote']++;
// the buffer holds a valid opening tag
if ($config['max_quote_depth'] && sizeof($close_tags) >= $config['max_quote_depth'])
{
if ($config['max_quote_depth'] == 1)
{
// Depth 1 - no nesting is allowed
$error_ary['quote_depth'] = $user->lang('QUOTE_NO_NESTING');
}
else
{
// There are too many nested quotes
$error_ary['quote_depth'] = $user->lang('QUOTE_DEPTH_EXCEEDED', (int) $config['max_quote_depth']);
}
$out .= $buffer . $tok;
$tok = '[]';
$buffer = '';
continue;
}
array_push($close_tags, '/quote:' . $this->bbcode_uid);
if (isset($m[1]) && $m[1])
@ -1308,6 +1286,12 @@ class parse_message extends bbcode_firstpass
// Parse this message
$this->message = $parser->parse(htmlspecialchars_decode($this->message, ENT_QUOTES));
// Remove quotes that are nested too deep
if ($config['max_quote_depth'] > 0)
{
$this->remove_nested_quotes($config['max_quote_depth']);
}
// Check for "empty" message. We do not check here for maximum length, because bbcode, smilies, etc. can add to the length.
// The maximum length check happened before any parsings.
if ($mode === 'post' && utf8_clean_string($this->message) === '')
@ -1904,6 +1888,63 @@ class parse_message extends bbcode_firstpass
$this->message = $tmp_message;
}
/**
* Remove nested quotes at given depth in current parsed message
*
* @param integer $max_depth Depth limit
* @return null
*/
public function remove_nested_quotes($max_depth)
{
global $phpbb_container;
if (preg_match('#^<[rt][ >]#', $this->message))
{
$this->message = $phpbb_container->get('text_formatter.utils')->remove_bbcode(
$this->message,
'quote',
$max_depth
);
return;
}
// Capture all [quote] and [/quote] tags
preg_match_all('(\\[/?quote(?:=&quot;(.*?)&quot;)?:' . $this->bbcode_uid . '\\])', $this->message, $matches, PREG_OFFSET_CAPTURE);
// Iterate over the quote tags to mark the ranges that must be removed
$depth = 0;
$ranges = array();
$start_pos = 0;
foreach ($matches[0] as $match)
{
if ($match[0][1] === '/')
{
--$depth;
if ($depth == $max_depth)
{
$end_pos = $match[1] + strlen($match[0]);
$length = $end_pos - $start_pos;
$ranges[] = array($start_pos, $length);
}
}
else
{
++$depth;
if ($depth == $max_depth + 1)
{
$start_pos = $match[1];
}
}
}
foreach (array_reverse($ranges) as $range)
{
list($start_pos, $length) = $range;
$this->message = substr_replace($this->message, '', $start_pos, $length);
}
}
/**
* Setter function for passing the plupload object
*

View File

@ -1586,13 +1586,12 @@ if (!sizeof($error) && $preview)
// Remove quotes that would become nested too deep before decoding the text
$generate_quote = ($mode == 'quote' && !$submit && !$preview && !$refresh);
if ($generate_quote && $config['max_quote_depth'] > 0 && preg_match('#^<[rt][ >]#', $message_parser->message))
if ($generate_quote && $config['max_quote_depth'] > 0)
{
$message_parser->message = $phpbb_container->get('text_formatter.utils')->remove_bbcode(
$message_parser->message,
'quote',
$config['max_quote_depth'] - 1
);
$tmp_bbcode_uid = $message_parser->bbcode_uid;
$message_parser->bbcode_uid = $post_data['bbcode_uid'];
$message_parser->remove_nested_quotes($config['max_quote_depth'] - 1);
$message_parser->bbcode_uid = $tmp_bbcode_uid;
}
// Decode text for message display