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

Commit b92e64f

Browse files
committed
Use jsesc for proper escaping.
Use @mathias https://github.com/mathiasbynens/jsesc package to perform the proper escaping of special characters.
1 parent eb66965 commit b92e64f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5+
const jsesc = require('jsesc');
6+
57
module.exports = function(content) {
68
this.cacheable && this.cacheable();
79
this.value = content;
8-
content = JSON.stringify(content)
9-
.replace(/\u2028/g, '\\u2028')
10-
.replace(/\u2029/g, '\\u2029');
11-
return `module.exports = ${content}`;
10+
content = JSON.stringify(content);
11+
content = jsesc(content);
12+
return 'module.exports = ' + content;
1213
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
"type": "git",
88
"url": "git@github.com:webpack/raw-loader.git"
99
},
10-
"license": "MIT"
10+
"license": "MIT",
11+
"dependencies": {
12+
"jsesc": "^2.5.1"
13+
}
1114
}

0 commit comments

Comments
 (0)