-
-
Notifications
You must be signed in to change notification settings - Fork 90
fix(index): escape invalid characters #43
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
/* | ||
MIT License http://www.opensource.org/licenses/mit-license.php | ||
Author Tobias Koppers @sokra | ||
MIT License http://www.opensource.org/licenses/mit-license.php | ||
Author Tobias Koppers @sokra | ||
*/ | ||
module.exports = function(content) { | ||
this.cacheable && this.cacheable(); | ||
this.value = content; | ||
return "module.exports = " + JSON.stringify(content); | ||
module.exports = function(source) { | ||
this.cacheable && this.cacheable(); | ||
this.value = source; | ||
|
||
var json = JSON.stringify(source) | ||
.replace(/\u2028/g, '\\u2028') | ||
.replace(/\u2029/g, '\\u2029'); | ||
|
||
return "module.exports = " + json; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, the problem I had was that I was importing a file which had these special characters and it turns out that they break JSON. See the MDN article I posted above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I know. But why converting to json is better than wrapping the string with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really, it's a matter of choice. I've been used to using json stringify for things like this where code gets evaluated. But yeah, you are right, it is the same. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't support webpack 1.x. Cachable can be removed at this point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok