From 76bd270932f6b352136e6636f182cbc631b62985 Mon Sep 17 00:00:00 2001 From: Andrew Hyndman Date: Sat, 2 Apr 2016 19:13:41 +1100 Subject: [PATCH] Escape Newline/Paragraph separators I think that the Webpack JSON loader seems like the right place to handle this issue. For whatever reason, the JSON and Javascript specifications disagree on whether or not strings can contain the unicode Newline or Paragraph characters. In the case that a JSON object containing one of these characters is being printed to a script tag, we should escape them. See also, this discussion: https://github.com/expressjs/express/issues/1132#issuecomment-10100419 --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index bb7b2c0..f3d92c3 100644 --- a/index.js +++ b/index.js @@ -6,5 +6,9 @@ module.exports = function(source) { this.cacheable && this.cacheable(); var value = typeof source === "string" ? JSON.parse(source) : source; this.value = [value]; - return "module.exports = " + JSON.stringify(value) + ";"; + return "module.exports = " + + JSON.stringify(value) + .replace(/\u2028/g, '\\u2028') + .replace(/\u2029/g, '\\u2029') + + ";"; }