From 11c768d3c07c178c8b4221b0cd721ab7f92b68bc Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 4 Jan 2021 07:47:40 -0800 Subject: [PATCH] Fixes shortcode wrapper conflict within the same template. --- e107_handlers/shortcode_handler.php | 12 ++++------- .../_blank/templates/_blank_template.php | 5 ++++- .../tests/unit/e_parse_shortcodeTest.php | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/e107_handlers/shortcode_handler.php b/e107_handlers/shortcode_handler.php index 2372dd576..ce95f12a5 100644 --- a/e107_handlers/shortcode_handler.php +++ b/e107_handlers/shortcode_handler.php @@ -823,21 +823,17 @@ class e_parse_shortcode // Do it only once per parsing cylcle and not on every doCode() loop - performance if(method_exists($this->addedCodes, 'wrapper')) { - // $cname = get_class($this->addedCodes); - $tmpWrap = e107::templateWrapper($this->addedCodes->wrapper()); + $this->wrapper = $this->addedCodes->getWrapperID(); + if(!empty($tmpWrap)) // FIX for #3 above. { $this->wrappers = array_merge($this->wrappers,$tmpWrap); - $this->wrapper = $this->addedCodes->getWrapperID(); - } - elseif(E107_DBG_BBSC) + elseif(!empty($this->wrapper)) // if there's a wrapper id but no wrappers assigned to it, clear the wrappers array. { - $this->wrapper = $this->addedCodes->getWrapperID(); - // e107::getMessage()->addDebug("Wrapper Empty: ".$this->addedCodes->wrapper()); + $this->wrappers = array(); } - } if(method_exists($this->addedCodes, 'editable')) diff --git a/e107_plugins/_blank/templates/_blank_template.php b/e107_plugins/_blank/templates/_blank_template.php index c0134aeeb..92a40c2b7 100644 --- a/e107_plugins/_blank/templates/_blank_template.php +++ b/e107_plugins/_blank/templates/_blank_template.php @@ -10,4 +10,7 @@ $_BLANK_WRAPPER['default']['BLANK_TEST'] = "[ {---} ]"; - $_BLANK_TEMPLATE['default'] = "
{BLANK_TEST}
"; \ No newline at end of file + $_BLANK_TEMPLATE['default'] = "
{BLANK_TEST}
"; + + + $_BLANK_TEMPLATE['other'] = "
{BLANK_TEST}
"; \ No newline at end of file diff --git a/e107_tests/tests/unit/e_parse_shortcodeTest.php b/e107_tests/tests/unit/e_parse_shortcodeTest.php index a2fca91ba..e21623f6e 100644 --- a/e107_tests/tests/unit/e_parse_shortcodeTest.php +++ b/e107_tests/tests/unit/e_parse_shortcodeTest.php @@ -114,6 +114,9 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit $sc_style['BLANK_TEST']['post'] = " **"; $actualTemplate = e107::getTemplate('_blank', '_blank', 'default'); + $otherTemplate = e107::getTemplate('_blank', '_blank', 'other'); + + $expectedTemplate = "
{BLANK_TEST}
"; $this->assertEquals($expectedTemplate, $actualTemplate); $actualLegacy = $this->scParser->parseCodes($actualTemplate, false, $sc); @@ -124,6 +127,24 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit $sc->wrapper('_blank/default'); // overrides legacy $sc_style; $actual = $this->scParser->parseCodes($actualTemplate, false, $sc); $expected = "
[ test ]
"; + $this->assertEquals($expected, $actual); + + // different template, same wrapper ID. + $actual = $this->scParser->parseCodes($otherTemplate, false, $sc); + $expected = "
[ test ]
"; + $this->assertEquals($expected, $actual); + + // different template and non-existent wrappers - should fallback to legacy wrappers and not use '_blank/default' wrappers by the same name. + $sc->wrapper('_blank/other'); + $actual = $this->scParser->parseCodes($otherTemplate, false, $sc); + $expected = "
** test **
"; + $this->assertEquals($expected, $actual); + + + // And back to a wrapper that exists. + $sc->wrapper('_blank/default'); // overrides legacy $sc_style; + $actual = $this->scParser->parseCodes($otherTemplate, false, $sc); + $expected = "
[ test ]
"; $this->assertEquals($expected, $actual);