aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorTristan Darricau <tristan.darricau@sensiolabs.com>2015-06-29 11:33:00 +0200
committerTristan Darricau <tristan.darricau@sensiolabs.com>2015-06-29 11:33:00 +0200
commit2be39c5a8f3b587f2fe091862e7021ae70d9fcda (patch)
tree27ee4c883d69aa541977f795ab64831948ff40db /phpBB/includes
parent7b903919bf17856fa1f16d9ad386c4b47e48bc81 (diff)
parentae2237f640c5f08924b01e780d9549dddcb1b7da (diff)
downloadforums-2be39c5a8f3b587f2fe091862e7021ae70d9fcda.tar
forums-2be39c5a8f3b587f2fe091862e7021ae70d9fcda.tar.gz
forums-2be39c5a8f3b587f2fe091862e7021ae70d9fcda.tar.bz2
forums-2be39c5a8f3b587f2fe091862e7021ae70d9fcda.tar.xz
forums-2be39c5a8f3b587f2fe091862e7021ae70d9fcda.zip
Merge pull request #3654 from s9e/ticket/13880
[ticket/13880] Automatically remove quotes that are nested too deep
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/message_parser.php72
1 files changed, 50 insertions, 22 deletions
diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php
index 42ca9bf09d..8b3d8d9fd5 100644
--- a/phpBB/includes/message_parser.php
+++ b/phpBB/includes/message_parser.php
@@ -791,28 +791,6 @@ class bbcode_firstpass extends bbcode
else if (preg_match('#^quote(?:=&quot;(.*?)&quot;)?$#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])
@@ -1277,6 +1255,12 @@ class parse_message extends bbcode_firstpass
return $update_this_message ? $this->warn_msg : $return_message;
}
+ // 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) === '')
@@ -1856,6 +1840,50 @@ class parse_message extends bbcode_firstpass
}
/**
+ * 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)
+ {
+ // 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
*
* @param \phpbb\plupload\plupload $plupload The plupload object