Skip to content

Smarty v5 built-in json_encode modifier doesn't take Smarty $_CHARSET encoding into account, and can't be overridden using registerPlugin() #1011

@cmanley

Description

@cmanley

I manage a couple of websites, some of which use cp1252 encoding.
It's in these websites, the json_encode modifier sometimes returns false when given cp1252 encoded data.
This used to work with Smarty v3 and v4 where I registered my own json_encode modifier that does the input encoding conversion automatically based on the Smarty $_CHARSET encoding.
After some debugging, I noticed that my custom and registered modifier isn't being called at all in v5, but instead the built-in Smarty json_encode() modifier is being used.

I've tried to unregister the built-in json_encode modifier first before registering my custom modifier but that doesn't seem to have any effect:

$smarty->unregisterPlugin('modifier',  'json_encode');
$smarty->unregisterPlugin('function', 'json_encode');
$smarty->registerPlugin('modifier', 'json_encode', [$this, 'modifier_json_encode']);

If the json_encode modifier is to ignore the $_CHARSET encoding by design, then how do I override a built-in modifier/function with a customized one in v5?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions