diff --git a/composer.json b/composer.json index acc00b0..5398c21 100644 --- a/composer.json +++ b/composer.json @@ -16,11 +16,15 @@ ], "require": { "php": ">= 7.2", - "nette/utils": "^3.2.5" + "ext-json": "*" }, "require-dev": { - "phpstan/phpstan": "^0.12.98", - "nette/tester": "^2.4" + "nette/tester": "^2.4", + "nette/utils": "^3.2.5", + "phpstan/phpstan": "^0.12.98" + }, + "suggest": { + "nette/utils": "Allows to safe escape HTML with markup: https://doc.nette.org/en/utils/html-elements" }, "autoload": { "psr-4": { @@ -30,5 +34,8 @@ "scripts": { "phpstan": "phpstan analyze src -c phpstan.neon --level 7", "tester": "tester tests" + }, + "config": { + "sort-packages": true } } diff --git a/src/Escape.php b/src/Escape.php index dc3d322..cf8e403 100644 --- a/src/Escape.php +++ b/src/Escape.php @@ -7,7 +7,7 @@ use Nette\HtmlStringable; use Nette\Utils\IHtmlString; -use Nette\Utils\Json; +use RuntimeException; /** * Escape funxtions. Uses UTF-8 only. @@ -99,7 +99,11 @@ public static function js($data): string $data = (string)$data; } - $json = Json::encode($data); + $json = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRESERVE_ZERO_FRACTION); + + if ($json === false) { + throw new RuntimeException("JSON encode failed: " . json_last_error_msg(), json_last_error()); + } return str_replace([']]>', '