Skip to content
This repository was archived by the owner on Aug 20, 2018. It is now read-only.

Commit 76bd270

Browse files
ajhyndmanlaughinghan
authored andcommitted
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: expressjs/express#1132 (comment)
1 parent 4cf55b7 commit 76bd270

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@ module.exports = function(source) {
66
this.cacheable && this.cacheable();
77
var value = typeof source === "string" ? JSON.parse(source) : source;
88
this.value = [value];
9-
return "module.exports = " + JSON.stringify(value) + ";";
9+
return "module.exports = " +
10+
JSON.stringify(value)
11+
.replace(/\u2028/g, '\\u2028')
12+
.replace(/\u2029/g, '\\u2029') +
13+
";";
1014
}

0 commit comments

Comments
 (0)