[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Parser: fix nested no-parse blocks causing leaks and textarea spacing

"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6a26dcfc79454_381949ac34635@gitlab-sidekiq-low-urgency-cpu-bound-v2-69c56fdcb-5dmll.mail>

Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
7185d64f by MAGENE Sem Joel at 2026-06-08T14:58:32+00:00
[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

- - - - -


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
=====================================
@@ -73,6 +73,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/7185d64fb8fb3c0973e4ec060510deecf7a9b665

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/7185d64fb8fb3c0973e4ec060510deecf7a9b665
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.