Skip to content

Commit

Permalink
Merge pull request #7 from satazor/escape-str
Browse files Browse the repository at this point in the history
Escape moduleId and css contents
  • Loading branch information
faceyspacey authored May 7, 2017
2 parents ab32e74 + 4e60248 commit 1583300
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
var path = require("path");
var fs = require("fs");
var loaderUtils = require("loader-utils");
var jsesc = require("jsesc");
var NodeTemplatePlugin = require("webpack/lib/node/NodeTemplatePlugin");
var NodeTargetPlugin = require("webpack/lib/node/NodeTargetPlugin");
var LibraryTemplatePlugin = require("webpack/lib/LibraryTemplatePlugin");
Expand Down Expand Up @@ -130,12 +131,14 @@ module.exports.pitch = function(request) {
if (text.locals) {
resultSource += "\nmodule.exports = " + JSON.stringify(text.locals) + ";";
}

// module.hot.data is undefined on initial load, and an object in hot updates
var jsescOpts = { wrap: true, quotes: "double" };
resultSource += `
/*__START_CSS__*/
var moduleId = "${text[0][0]}";
var css = "${text[0][1].split("\n").join("")}";
var addStyles = require("style-loader/addStyles.js");
/*__START_CSS__*/
var moduleId = ${jsesc(text[0][0], jsescOpts)};
var css = ${jsesc(text[0][1], jsescOpts)};
var addStyles = require("style-loader/addStyles.js");
addStyles([[moduleId, css]], "");
/*__END_CSS__*/
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"ajv": "^4.11.2",
"async": "^2.1.2",
"jsesc": "^2.5.1",
"loader-utils": "^1.0.2",
"style-loader": "^0.16.1",
"webpack-sources": "^0.2.3"
Expand Down

0 comments on commit 1583300

Please sign in to comment.