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

Commit be7abf1

Browse files
committed
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 1409807 commit be7abf1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

index.js

+5-1
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, undefined, "\t") + ";";
9+
return "module.exports = " +
10+
JSON.stringify(value, undefined, "\t")
11+
.replace(/\u2028/g, '\\u2028')
12+
.replace(/\u2029/g, '\\u2029') +
13+
";";
1014
}

0 commit comments

Comments
 (0)