From 4e602481cd7394238e7e6f35c8a1593165deedfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Cruz?= Date: Sun, 7 May 2017 10:56:37 +0100 Subject: [PATCH] Escape moduleId and css contents. --- loader.js | 11 +++++++---- package.json | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/loader.js b/loader.js index 6bf86f0d..b2602281 100644 --- a/loader.js +++ b/loader.js @@ -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"); @@ -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__*/ diff --git a/package.json b/package.json index 3959f0c2..e87b74dc 100644 --- a/package.json +++ b/package.json @@ -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"