From 9dff3f302ce40117f299b24e3e494e5c90c596da Mon Sep 17 00:00:00 2001 From: Mourad Date: Sat, 27 Feb 2016 17:58:25 +0100 Subject: [PATCH] fix(karma): Escape quotes for file names. This fixes issue #1876. fix(karma): Escape quotes for file names. This fixes issue #1876. --- lib/middleware/karma.js | 3 +++ test/unit/middleware/karma.spec.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/middleware/karma.js b/lib/middleware/karma.js index a36a53617..2e603b382 100644 --- a/lib/middleware/karma.js +++ b/lib/middleware/karma.js @@ -151,6 +151,9 @@ var createKarmaMiddleware = function (filesPromise, serveStaticFile, serveFile, var mappings = files.served.map(function (file) { // Windows paths contain backslashes and generate bad IDs if not escaped var filePath = filePathToUrlPath(file.path, basePath, urlRoot).replace(/\\/g, '\\\\') + // Escape single quotes that might be in the filename - + // double quotes should not be allowed! + filePath = filePath.replace(/'/g, '\\\'') return util.format(" '%s': '%s'", filePath, file.sha) }) diff --git a/test/unit/middleware/karma.spec.js b/test/unit/middleware/karma.spec.js index c7e905792..534a33453 100644 --- a/test/unit/middleware/karma.spec.js +++ b/test/unit/middleware/karma.spec.js @@ -282,6 +282,21 @@ describe('middleware.karma', () => { callHandlerWith('/__karma__/context.html') }) + it('should escape quotes in mappings with all served files', (done) => { + fsMock._touchFile('/karma/static/context.html', 0, '%MAPPINGS%') + servedFiles([ + new MockFile("/some/abc/a'b.js", 'sha_a'), + new MockFile('/base/path/ba.js', 'sha_b') + ]) + + response.once('end', () => { + expect(response).to.beServedAs(200, 'window.__karma__.files = {\n \'/__karma__/absolute/some/abc/a\\\'b.js\': \'sha_a\',\n \'/__karma__/base/ba.js\': \'sha_b\'\n};\n') + done() + }) + + callHandlerWith('/__karma__/context.html') + }) + it('should serve debug.html with replaced script tags without timestamps', (done) => { includedFiles([ new MockFile('/first.js'),