01556: Two bugs in pm_json_encode()

Summary: Two bugs in pm_json_encode()
Created: 2026-05-25 17:10
Status: ToDo
Category: Bug
Assigned:
Priority: 1
Version: 2.6.0
OS: 8.2

Description: This bug has existed since pmwiki-2.3.36 and only occurs if the wiki uses a encoding OTHER than UTF-8!

Effect of the error: If the "config.php" file contains the following entries: "$EnablePmSyntax = 1;" and "XLPage('de','PmWikiDe.XLPage');" the "Einfärbung" (Highlight) button will be missing.

The problem is that the configuration is passed to JavaScript from "config.php" via JSON, and this can only be done using UTF-8 encoding. In my opinion, the PHP function json_encode() is very unreliable, as it fails at the slightest glitch.

The problem can be fixed in "pmwiki.php" using the "pm_json_encode()" function. Lines 952–953 (pmwiki-2.6.0) read:

  if (function_exists('json_encode'))
    $out = json_encode($x);

and should be changed to:

  if (function_exists('json_encode') and
    $out = json_encode($x));

Then, right below that, on line 956, another error occurs:

    $out = '"'.preg_replace_callback("/[\x00-\x1f\\/\\\\\"]/",'cb_rfc8259',$x).'"';

A null byte must not appear in a regular expression and can be easily fixed:

    $out = '"'.preg_replace_callback('/[\x00-\x1f\\/\\\\"]/','cb_rfc8259',$x).'"';

That should fix the bugs, and the feature should now work as intended. Michael Engelke

Thanks for this report, yes it is a known problem if the wiki has not enabled UTF-8. I think you mean "$EnablePmSyntax = 2;" not "1". I think we should try to recode the JS arrays to UTF-8. --Petko