From 0616dda489d07f6a9bc3def1778dcef601411821 Mon Sep 17 00:00:00 2001 From: Paul Sweeney Date: Wed, 13 Dec 2017 04:05:21 -0800 Subject: [PATCH] fix: use `os.tmpdir()` to safely store `_karma_webpack_` (#279) --- src/karma-webpack.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/karma-webpack.js b/src/karma-webpack.js index 6005b29..c3b6c3c 100644 --- a/src/karma-webpack.js +++ b/src/karma-webpack.js @@ -1,3 +1,4 @@ +var os = require('os') var _ = require('lodash') var path = require('path') var async = require('async') @@ -47,8 +48,8 @@ function Plugin( // Must have the common _karma_webpack_ prefix on path here to avoid // https://github.com/webpack/webpack/issues/645 - webpackOptions.output.path = '/_karma_webpack_/' + indexPath - webpackOptions.output.publicPath = '/_karma_webpack_/' + publicPath + webpackOptions.output.path = path.join(os.tmpdir(), '_karma_webpack_', indexPath) + webpackOptions.output.publicPath = path.join(os.tmpdir(), '_karma_webpack_', publicPath) webpackOptions.output.filename = '[name]' if (includeIndex) { webpackOptions.output.jsonpFunction = 'webpackJsonp' + index @@ -132,11 +133,11 @@ function Plugin( } }.bind(this)) - webpackMiddlewareOptions.publicPath = '/_karma_webpack_/' + webpackMiddlewareOptions.publicPath = path.join(os.tmpdir(), '_karma_webpack_') var middleware = this.middleware = new webpackDevMiddleware(compiler, webpackMiddlewareOptions) customFileHandlers.push({ - urlRegex: /^\/_karma_webpack_\/.*/, + urlRegex: new RegExp('^' + os.tmpdir() + '\/_karma_webpack_\/.*/'), handler: function(req, res) { middleware(req, res, function() { res.statusCode = 404 @@ -197,7 +198,7 @@ Plugin.prototype.readFile = function(file, callback) { var doRead = function() { if (optionsCount > 1) { async.times(optionsCount, function(idx, callback) { - middleware.fileSystem.readFile('/_karma_webpack_/' + idx + '/' + file.replace(/\\/g, '/'), callback) + middleware.fileSystem.readFile(path.join(os.tmpdir(), '_karma_webpack_', idx, file.replace(/\\/g, '/')), callback) }, function(err, contents) { if (err) { return callback(err) @@ -214,7 +215,7 @@ Plugin.prototype.readFile = function(file, callback) { }) } else { try { - var fileContents = middleware.fileSystem.readFileSync('/_karma_webpack_/' + file.replace(/\\/g, '/')) + var fileContents = middleware.fileSystem.readFileSync(path.join(os.tmpdir(), '_karma_webpack_', file.replace(/\\/g, '/'))) callback(undefined, fileContents) } catch (e) {