1
0
mirror of https://github.com/e107inc/e107.git synced 2025-06-04 09:54:56 +02:00

Fixes shortcode wrapper conflict within the same template.

This commit is contained in:
Cameron 2021-01-04 07:47:40 -08:00
parent f20f00408c
commit 11c768d3c0
3 changed files with 29 additions and 9 deletions

View File

@ -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'))

View File

@ -10,4 +10,7 @@
$_BLANK_WRAPPER['default']['BLANK_TEST'] = "[ {---} ]";
$_BLANK_TEMPLATE['default'] = "<div>{BLANK_TEST}</div>";
$_BLANK_TEMPLATE['default'] = "<div>{BLANK_TEST}</div>";
$_BLANK_TEMPLATE['other'] = "<div>{BLANK_TEST}</div>";

View File

@ -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 = "<div>{BLANK_TEST}</div>";
$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 = "<div>[ test ]</div>";
$this->assertEquals($expected, $actual);
// different template, same wrapper ID.
$actual = $this->scParser->parseCodes($otherTemplate, false, $sc);
$expected = "<div>[ test ]</div>";
$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 = "<div>** test **</div>";
$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 = "<div>[ test ]</div>";
$this->assertEquals($expected, $actual);