Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
dont escape slashes in encoded json, fixes #67
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlindhe committed Nov 26, 2018
1 parent c1f8692 commit 32dc7f8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function generateFromPath($path, $umd = null, $withVendor = false)

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

$jsonLocales = json_encode($locales, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . PHP_EOL;
$jsonLocales = json_encode($locales, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL;

if(json_last_error() !== JSON_ERROR_NONE)
{
Expand Down Expand Up @@ -136,7 +136,7 @@ public function generateMultiple($path, $umd = null)
foreach ($this->filesToCreate as $fileName => $data) {
$fileToCreate = $jsPath . $fileName . '.js';
$createdFiles .= $fileToCreate . PHP_EOL;
$jsonLocales = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . PHP_EOL;
$jsonLocales = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL;
if(json_last_error() !== JSON_ERROR_NONE)
{
throw new Exception('Could not generate JSON, error code '.json_last_error());
Expand Down
4 changes: 3 additions & 1 deletion tests/GenerateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ function testShouldNotTouchHtmlTags()
'help' => [
'yes' => 'see <a href="mailto:mail@com">',
'no' => 'see <a href=":link">',
'maybe' => 'It is a <strong>Test</strong> ok!',
]
]
];
Expand All @@ -264,7 +265,8 @@ function testShouldNotTouchHtmlTags()
. ' "en": {' . PHP_EOL
. ' "help": {' . PHP_EOL
. ' "yes": "see <a href=\"mailto:mail@com\">",' . PHP_EOL
. ' "no": "see <a href=\"{link}\">"' . PHP_EOL
. ' "no": "see <a href=\"{link}\">",' . PHP_EOL
. ' "maybe": "It is a <strong>Test</strong> ok!"' . PHP_EOL
. ' }' . PHP_EOL
. ' }' . PHP_EOL
. '}' . PHP_EOL,
Expand Down

0 comments on commit 32dc7f8

Please sign in to comment.