[TikiWiki-commits] [Git][tikiwiki/tiki][30.x] [BP][FIX] Parser: fix nested no-parse blocks causing leaks and textarea spacing
"MAGENE Sem Joel \(@Jomagene\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6a27123ebb8ee_381948a838769@gitlab-sidekiq-low-urgency-cpu-bound-v2-5d4745456c-p76hq.mail> |
MAGENE Sem Joel pushed to branch 30.x at Tiki Wiki CMS Groupware / Tiki
Commits:
c94474e9 by MAGENE Sem Joel at 2026-06-08T18:57:48+00:00
[BP][FIX] Parser: fix nested no-parse blocks causing leaks and textarea spacing
---
* [FIX] Parser: fix nested no-parse blocks causing leaks and textarea spacing
---
* [FIX] Parser: fix nested no-parse blocks causing leaks and textarea spacing
See merge request tikiwiki/tiki!10448
(cherry picked from commit 7185d64fb8fb3c0973e4ec060510deecf7a9b665)
See merge request tikiwiki/tiki!10467
- - - - -
2 changed files:
- lib/parser/parserlib.php
- lib/test/TikiLib/WikiParserTest.php
Changes:
=====================================
lib/parser/parserlib.php
=====================================
@@ -479,8 +479,12 @@ class ParserLib extends TikiDb_Bridge
$start = -1;
while (false !== $start = strpos($data, '~np~', $start + 1)) {
- if (false !== $end = strpos($data, '~/np~', $start)) {
+ $nested = false;
+ if (false !== $end = $this->findUnparsedBlockEnd($data, $start, $nested)) {
$content = substr($data, $start + 4, $end - $start - 4);
+ if ($nested) {
+ $content = str_replace(['~np~', '~/np~'], '', $content);
+ }
if ($protect) {
$content = $this->protectSpecialChars($content, $this->option['is_html']);
}
@@ -494,6 +498,37 @@ class ParserLib extends TikiDb_Bridge
}
}
+ private function findUnparsedBlockEnd($data, $start, &$nested = false)
+ {
+ $search = $start + 4;
+ $depth = 1;
+ $firstClose = false;
+ $nested = false;
+
+ while (false !== $nextClose = strpos($data, '~/np~', $search)) {
+ if ($firstClose === false) {
+ $firstClose = $nextClose;
+ }
+
+ $nextOpen = strpos($data, '~np~', $search);
+ if ($nextOpen !== false && $nextOpen < $nextClose) {
+ $depth++;
+ $search = $nextOpen + 4;
+ continue;
+ }
+
+ $depth--;
+ if ($depth === 0) {
+ $nested = $nextClose !== $firstClose;
+ return $nextClose;
+ }
+
+ $search = $nextClose + 5;
+ }
+
+ return $firstClose;
+ }
+
//
// Call 'wikiplugin_.*_description()' from given file
//
=====================================
lib/test/TikiLib/WikiParserTest.php
=====================================
@@ -29,6 +29,35 @@ class TikiLib_WikiParserTest extends PHPUnit\Framework\TestCase
$this->assertEquals($output, TikiLib::lib('parser')->parse_data($input, $options));
}
+ /**
+ * @covers ParserLib::parse_data
+ */
+ public function testNestedNoParseBlocksProtectPluginHtml(): void
+ {
+ global $prefs;
+ $prefs['feature_wiki_paragraph_formatting'] = 'y';
+
+ $input = '~np~<div class="outer">
+<span>~np~Warning~/np~</span>
+
+<div class="edit-zone">
+ <textarea name="body"></textarea>
+</div>
+
+
+<input type="hidden" name="wysiwyg" value="n" />
+</div>~/np~';
+
+ $output = TikiLib::lib('parser')->parse_data($input, ['is_html' => true]);
+
+ $this->assertStringContainsString('<span>Warning</span>', $output);
+ $this->assertStringContainsString('<textarea name="body"></textarea>', $output);
+ $this->assertStringContainsString('<input type="hidden" name="wysiwyg" value="n" />', $output);
+ $this->assertStringNotContainsString('~np~', $output);
+ $this->assertStringNotContainsString('~/np~', $output);
+ $this->assertStringNotContainsString('<br /><br /><input type="hidden" name="wysiwyg"', $output);
+ }
+
public static function provider(): array
{
return [
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/c94474e90e17308f2f1086d7795e0c4fe42fa41f
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/c94474e90e17308f2f1086d7795e0c4fe42fa41f
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs