Skip to content

Commit

Permalink
fix(karma): Escape quotes for file names. This fixes issue #1876.
Browse files Browse the repository at this point in the history
fix(karma): Escape quotes for file names. This fixes issue #1876.
  • Loading branch information
Moumi committed Feb 28, 2016
1 parent 8d5d441 commit 9dff3f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/middleware/karma.js
Expand Up @@ -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)
})
Expand Down
15 changes: 15 additions & 0 deletions test/unit/middleware/karma.spec.js
Expand Up @@ -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'),
Expand Down

0 comments on commit 9dff3f3

Please sign in to comment.