From 46b6927447b5ee7562904a94fcf3f3cf5b522897 Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 19 Feb 2021 16:07:12 -0800 Subject: [PATCH] Fixes #4403 - Parsing of [code]. Test added. --- e107_handlers/e_parse_class.php | 22 +++++----------------- e107_tests/tests/unit/e_parseTest.php | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 36b6f4d86..8f3640f53 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -1496,7 +1496,7 @@ class e_parse { // Split each text block into bits which are either within one of the 'key' bbcodes, or outside them // (Because we have to match end words, the 'extra' capturing subpattern gets added to output array. We strip it later) - $content = preg_split('#(\[(table|html|php|code|scode|hide).*?\[/(?:\\2)\])#mis', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); + $content = preg_split('#(\[(table|html|php|code|scode|hide).*?\[\/(?:\\2)\])#mis', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); } @@ -1519,25 +1519,13 @@ class e_parse $opts = $saveOpts; + // Have to have a good test in case a 'non-key' bbcode starts the block // - so pull out the bbcode parameters while we're there if(($parseBB !== false) && preg_match('#(^\[(table|html|php|code|scode|hide)(.*?)\])(.*?)(\[/\\2\]$)#is', $full_text, $matches)) { - // It's one of the 'key' bbcodes - // Usually don't want 'normal' processing if its a 'special' bbcode - $proc_funcs = false; - // $matches[0] - complete block from opening bracket of opening tag to closing bracket of closing tag - // $matches[1] - complete opening tag (inclusive of brackets) - // $matches[2] - bbcode word - // $matches[3] - parameter, including '=' - // $matches[4] - bit between the tags (i.e. text to process) - // $matches[5] - closing tag - // In case we decide to load a file - // $bbPath = e_CORE . 'bbcodes/'; - // $bbFile = strtolower(str_replace('_', '', $matches[2])); - // $bbcode = ''; - // $className = ''; + $proc_funcs = false; $full_text = ''; $code_text = $matches[4]; // $parm = $matches[3] ? substr($matches[3], 1) : ''; @@ -1581,8 +1569,7 @@ class e_parse case 'scode': case 'code' : - $parseBB = false; - $full_text = $this->parseBBCodes('['.$last_bbcode.']'.$code_text.'[/'.$last_bbcode.']', $postID); + $full_text = $this->parseBBCodes($matches[0], $postID); break; } @@ -5435,6 +5422,7 @@ class e_parse } $text = str_replace(E_NL, $nl_replace, $text); + } return $text; diff --git a/e107_tests/tests/unit/e_parseTest.php b/e107_tests/tests/unit/e_parseTest.php index d576a7ef0..3a87fb238 100644 --- a/e107_tests/tests/unit/e_parseTest.php +++ b/e107_tests/tests/unit/e_parseTest.php @@ -458,10 +458,20 @@ while($row = $sql->fetch()) 'expected' => "\n\n
cell
", ), + 4 => array( + 'text' => "Test\n[b]first line[/b][b]\nsecond line[/b]", + 'expected' => "Test
first line
second line
", + ), + + 5 => array( + 'text' => "Test\n[code]1st [b]line[/b] of code[/code]\n[code]2nd line of code[/code]", + 'expected' => "Test
1st [b]line[/b] of code
2nd line of code
", + ), + ); - foreach($tests as $var) + foreach($tests as $index => $var) { $result = $this->tp->toHTML($var['text'], true); @@ -471,15 +481,13 @@ while($row = $sql->fetch()) continue; } - $this->assertEquals($var['expected'], $result); + $this->assertEquals($var['expected'], $result, 'Test #'.$index.' failed.'); } } - - public function testParseTemplateWithEnabledCoreShortcodes() { $needle = '