Skip to content

Commit 32dc7f8

Browse files
committed
dont escape slashes in encoded json, fixes martinlindhe#67
1 parent c1f8692 commit 32dc7f8

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Generator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function generateFromPath($path, $umd = null, $withVendor = false)
7676

7777
$locales = $this->adjustVendor($locales);
7878

79-
$jsonLocales = json_encode($locales, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . PHP_EOL;
79+
$jsonLocales = json_encode($locales, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL;
8080

8181
if(json_last_error() !== JSON_ERROR_NONE)
8282
{
@@ -136,7 +136,7 @@ public function generateMultiple($path, $umd = null)
136136
foreach ($this->filesToCreate as $fileName => $data) {
137137
$fileToCreate = $jsPath . $fileName . '.js';
138138
$createdFiles .= $fileToCreate . PHP_EOL;
139-
$jsonLocales = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . PHP_EOL;
139+
$jsonLocales = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL;
140140
if(json_last_error() !== JSON_ERROR_NONE)
141141
{
142142
throw new Exception('Could not generate JSON, error code '.json_last_error());

tests/GenerateTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ function testShouldNotTouchHtmlTags()
253253
'help' => [
254254
'yes' => 'see <a href="mailto:mail@com">',
255255
'no' => 'see <a href=":link">',
256+
'maybe' => 'It is a <strong>Test</strong> ok!',
256257
]
257258
]
258259
];
@@ -264,7 +265,8 @@ function testShouldNotTouchHtmlTags()
264265
. ' "en": {' . PHP_EOL
265266
. ' "help": {' . PHP_EOL
266267
. ' "yes": "see <a href=\"mailto:mail@com\">",' . PHP_EOL
267-
. ' "no": "see <a href=\"{link}\">"' . PHP_EOL
268+
. ' "no": "see <a href=\"{link}\">",' . PHP_EOL
269+
. ' "maybe": "It is a <strong>Test</strong> ok!"' . PHP_EOL
268270
. ' }' . PHP_EOL
269271
. ' }' . PHP_EOL
270272
. '}' . PHP_EOL,

0 commit comments

Comments
 (0)