Skip to content

Commit 751caca

Browse files
authored
Merge pull request #2 from kevcenteno/fix-string-escapes
Fix string escapes
2 parents c28bea2 + 0ca3d79 commit 751caca

File tree

7 files changed

+682
-264
lines changed

7 files changed

+682
-264
lines changed

lib/cli.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ function parse (source) {
9595
}
9696
}
9797

98-
return JSON.stringify(parsed, null, options.indent) + (options.insertFinalNewline ? "\n" : "");
98+
return JSON.stringify(parsed, null, options.indent).replace(/[^\n\r\ \x20-\x7e]/g, function(char) {
99+
return '\\u' + ('0000' + Number(char.charCodeAt(0)).toString(16)).match(/....$/)[0];
100+
}) + (options.insertFinalNewline ? "\n" : "");
99101
} catch (e) {
100102
if (options.forcePrettyPrint) {
101103
/* From https://github.com/umbrae/jsonlintdotcom:

0 commit comments

Comments
 (0)