aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/textformatter/s9e/bbcode_merger.php
diff options
context:
space:
mode:
authorJoshyPHP <s9e.dev@gmail.com>2019-11-25 18:34:04 +0100
committerJoshyPHP <s9e.dev@gmail.com>2019-11-25 18:34:04 +0100
commitd6f5b5ef6cd052d43f4bf75af423eaafd8ba9b07 (patch)
tree39d8da38b92d9c472c51b419bd98873f70ebf2c2 /phpBB/phpbb/textformatter/s9e/bbcode_merger.php
parentbf96786cda17d7f9505bc311179fe234cac49094 (diff)
downloadforums-d6f5b5ef6cd052d43f4bf75af423eaafd8ba9b07.tar
forums-d6f5b5ef6cd052d43f4bf75af423eaafd8ba9b07.tar.gz
forums-d6f5b5ef6cd052d43f4bf75af423eaafd8ba9b07.tar.bz2
forums-d6f5b5ef6cd052d43f4bf75af423eaafd8ba9b07.tar.xz
forums-d6f5b5ef6cd052d43f4bf75af423eaafd8ba9b07.zip
[ticket/16228] Fix BBCodes merging
PHPBB3-16228
Diffstat (limited to 'phpBB/phpbb/textformatter/s9e/bbcode_merger.php')
-rw-r--r--phpBB/phpbb/textformatter/s9e/bbcode_merger.php26
1 files changed, 21 insertions, 5 deletions
diff --git a/phpBB/phpbb/textformatter/s9e/bbcode_merger.php b/phpBB/phpbb/textformatter/s9e/bbcode_merger.php
index a05ca3c2b8..264eb93782 100644
--- a/phpBB/phpbb/textformatter/s9e/bbcode_merger.php
+++ b/phpBB/phpbb/textformatter/s9e/bbcode_merger.php
@@ -50,7 +50,7 @@ class bbcode_merger
$with = $this->create_bbcode($with);
// Select the appropriate strategy for merging this BBCode
- if ($this->is_content_bbcode($without, $with))
+ if (!$this->is_optional_bbcode($without, $with) && $this->is_content_bbcode($without, $with))
{
$merged = $this->merge_content_bbcode($without, $with);
}
@@ -107,12 +107,12 @@ class bbcode_merger
/**
* Test whether the two definitions form a "content"-style BBCode
*
- * Such BBCodes include the [URL] BBCode, which uses its text content as
+ * Such BBCodes include the [url] BBCode, which uses its text content as
* attribute if none is provided
*
* @param array $without BBCode definition without an attribute
* @param array $with BBCode definition with an attribute
- * @return array Merged definition
+ * @return bool
*/
protected function is_content_bbcode(array $without, array $with)
{
@@ -123,6 +123,22 @@ class bbcode_merger
}
/**
+ * Test whether the two definitions form BBCode with an optional attribute
+ *
+ * @param array $without BBCode definition without an attribute
+ * @param array $with BBCode definition with an attribute
+ * @return bool
+ */
+ protected function is_optional_bbcode(array $without, array $with)
+ {
+ // Remove the default attribute from the definition
+ $with['usage'] = preg_replace('(=[^\\]]++)', '', $with['usage']);
+
+ // Test whether both definitions are the same, regardless of case
+ return strcasecmp($without['usage'], $with['usage']) === 0;
+ }
+
+ /**
* Merge the two BBCode definitions of a "content"-style BBCode
*
* @param array $without BBCode definition without an attribute
@@ -131,7 +147,7 @@ class bbcode_merger
*/
protected function merge_content_bbcode(array $without, array $with)
{
- // Convert [X={X}] into [X={X;useContent}]
+ // Convert [x={X}] into [x={X;useContent}]
$usage = preg_replace('(\\})', ';useContent}', $with['usage'], 1);
// Use the template from the definition that uses an attribute
@@ -143,7 +159,7 @@ class bbcode_merger
/**
* Merge the two BBCode definitions of a BBCode with an optional argument
*
- * Such BBCodes include the [QUOTE] BBCode, which takes an optional argument
+ * Such BBCodes include the [quote] BBCode, which takes an optional argument
* but otherwise does not behave differently
*
* @param array $without BBCode definition without an attribute