Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(karma): Fix issue regarding escape quotes #1938

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/middleware/karma.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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