Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
Use jsesc for proper escaping.
Browse files Browse the repository at this point in the history
Use @mathias https://github.com/mathiasbynens/jsesc package to perform
the proper escaping of special characters.
  • Loading branch information
bmeurer committed Sep 28, 2017
1 parent eb66965 commit b92e64f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
const jsesc = require('jsesc');

module.exports = function(content) {
this.cacheable && this.cacheable();
this.value = content;
content = JSON.stringify(content)
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029');
return `module.exports = ${content}`;
content = JSON.stringify(content);
content = jsesc(content);
return 'module.exports = ' + content;
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"type": "git",
"url": "git@github.com:webpack/raw-loader.git"
},
"license": "MIT"
"license": "MIT",
"dependencies": {
"jsesc": "^2.5.1"
}
}

0 comments on commit b92e64f

Please sign in to comment.