From 709146b5804d7959f79c049c6a6f1885743398c5 Mon Sep 17 00:00:00 2001 From: Yaroslav Admin Date: Thu, 28 Oct 2021 21:49:52 +0200 Subject: [PATCH] fix(middleware): replace %X_UA_COMPATIBLE% marker anywhere in the file Previously %X_UA_COMPATIBLE% marker was only replaced if it was located at the start of the line. The limitation looks pretty arbitrary and caused the marker not to be replaced in the custom debug.html file used by Angular CLI as the marker was not located at the start of the line (probably because the file was re-formatted). This commit changes the behavior to replace the marker anywhere within the file, not just at the start of the line and thus fixes the problem for Angular CLI and potentially other people using custom files. Fixes #3711 --- lib/middleware/karma.js | 4 ++-- static/client.html | 2 +- static/debug.html | 2 +- test/unit/middleware/karma.spec.js | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/middleware/karma.js b/lib/middleware/karma.js index c92ae21a1..2535a2590 100644 --- a/lib/middleware/karma.js +++ b/lib/middleware/karma.js @@ -107,7 +107,7 @@ function createKarmaMiddleware ( } else { // serve client.html return serveStaticFile('/client.html', requestedRangeHeader, response, (data) => data - .replace('\n%X_UA_COMPATIBLE%', getXUACompatibleMetaElement(request.url)) + .replace('%X_UA_COMPATIBLE%', getXUACompatibleMetaElement(request.url)) .replace('%X_UA_COMPATIBLE_URL%', getXUACompatibleUrl(request.url))) } } @@ -226,7 +226,7 @@ function createKarmaMiddleware ( .replace('%CLIENT_CONFIG%', 'window.__karma__.config = ' + JSON.stringify(client) + ';\n') .replace('%SCRIPT_URL_ARRAY%', () => 'window.__karma__.scriptUrls = ' + JSON.stringify(scriptUrls) + ';\n') .replace('%MAPPINGS%', () => 'window.__karma__.files = {\n' + mappings.join(',\n') + '\n};\n') - .replace('\n%X_UA_COMPATIBLE%', getXUACompatibleMetaElement(request.url)) + .replace('%X_UA_COMPATIBLE%', getXUACompatibleMetaElement(request.url)) }) }) } else if (requestUrl === '/context.json') { diff --git a/static/client.html b/static/client.html index 4e069e1ef..73fb856a4 100644 --- a/static/client.html +++ b/static/client.html @@ -5,7 +5,7 @@ --> -%X_UA_COMPATIBLE% + %X_UA_COMPATIBLE% Karma diff --git a/static/debug.html b/static/debug.html index 3fc6173f2..e8c667674 100644 --- a/static/debug.html +++ b/static/debug.html @@ -6,7 +6,7 @@ --> -%X_UA_COMPATIBLE% + %X_UA_COMPATIBLE% Karma DEBUG RUNNER diff --git a/test/unit/middleware/karma.spec.js b/test/unit/middleware/karma.spec.js index b6a0d5d59..3a1c027f2 100644 --- a/test/unit/middleware/karma.spec.js +++ b/test/unit/middleware/karma.spec.js @@ -27,10 +27,10 @@ describe('middleware.karma', () => { const fsMock = mocks.fs.create({ karma: { static: { - 'client.html': mocks.fs.file(0, 'CLIENT HTML\n%X_UA_COMPATIBLE%%X_UA_COMPATIBLE_URL%'), + 'client.html': mocks.fs.file(0, 'CLIENT HTML%X_UA_COMPATIBLE%%X_UA_COMPATIBLE_URL%'), 'client_with_context.html': mocks.fs.file(0, 'CLIENT_WITH_CONTEXT\n%SCRIPT_URL_ARRAY%'), 'context.html': mocks.fs.file(0, 'CONTEXT\n%SCRIPTS%'), - 'debug.html': mocks.fs.file(0, 'DEBUG\n%SCRIPTS%\n%X_UA_COMPATIBLE%'), + 'debug.html': mocks.fs.file(0, 'DEBUG\n%SCRIPTS%%X_UA_COMPATIBLE%'), 'karma.js': mocks.fs.file(0, 'root: %KARMA_URL_ROOT%, proxy: %KARMA_PROXY_PATH%, v: %KARMA_VERSION%') } }