diff --git a/lib/middleware/serveResources.js b/lib/middleware/serveResources.js index cb03b5ae..cf0ec320 100644 --- a/lib/middleware/serveResources.js +++ b/lib/middleware/serveResources.js @@ -63,7 +63,7 @@ function createMiddleware({resourceCollections}) { let stream = resource.getStream(); - if ((type.startsWith("text/") || type === "application/javascript")) { + if (charset === "UTF-8" && (type.startsWith("text/") || type === "application/javascript")) { if (resource._project) { stream = stream.pipe(replaceStream("${version}", resource._project.version)); } else { diff --git a/test/fixtures/application.a/webapp/i18n/i18n_de.properties b/test/fixtures/application.a/webapp/i18n/i18n_de.properties new file mode 100644 index 00000000..dc888eff --- /dev/null +++ b/test/fixtures/application.a/webapp/i18n/i18n_de.properties @@ -0,0 +1 @@ +showHelloButtonText=Say ä! \ No newline at end of file diff --git a/test/fixtures/application.a/webapp/index.html b/test/fixtures/application.a/webapp/index.html index 77b0207c..3d8715b9 100644 --- a/test/fixtures/application.a/webapp/index.html +++ b/test/fixtures/application.a/webapp/index.html @@ -1,9 +1,9 @@ - Application A + Application A - Version ${version} - \ No newline at end of file + diff --git a/test/lib/server/acceptRemoteConnections.js b/test/lib/server/acceptRemoteConnections.js index 1565ed6d..c5a6e6f5 100644 --- a/test/lib/server/acceptRemoteConnections.js +++ b/test/lib/server/acceptRemoteConnections.js @@ -41,6 +41,6 @@ test("Get resource from application.a (/index.html) with enabled remote connecti } t.deepEqual(res.statusCode, 200, "Correct HTTP status code"); t.regex(res.headers["content-type"], /html/, "Correct content type"); - t.regex(res.text, /Application A<\/title>/, "Correct response"); + t.regex(res.text, /<title>Application A - Version 1.0.0<\/title>/, "Correct response"); }); }); diff --git a/test/lib/server/h2.js b/test/lib/server/h2.js index 45715bd6..1d016b0a 100644 --- a/test/lib/server/h2.js +++ b/test/lib/server/h2.js @@ -54,6 +54,6 @@ test("Get resource from application.a (/index.html)", (t) => { } t.deepEqual(res.statusCode, 200, "Correct HTTP status code"); t.regex(res.headers["content-type"], /html/, "Correct content type"); - t.regex(res.text, /<title>Application A<\/title>/, "Correct response"); + t.regex(res.text, /<title>Application A - Version 1.0.0<\/title>/, "Correct response"); }); }); diff --git a/test/lib/server/main.js b/test/lib/server/main.js index da710209..dd7d9283 100644 --- a/test/lib/server/main.js +++ b/test/lib/server/main.js @@ -21,7 +21,7 @@ test.before((t) => { }); }); -test.after(() => { +test.after.always(() => { return new Promise((resolve, reject) => { serve.close((error) => { if (error) { @@ -40,7 +40,7 @@ test("Get resource from application.a (/index.html)", (t) => { } t.deepEqual(res.statusCode, 200, "Correct HTTP status code"); t.regex(res.headers["content-type"], /html/, "Correct content type"); - t.regex(res.text, /<title>Application A<\/title>/, "Correct response"); + t.regex(res.text, /<title>Application A - Version 1.0.0<\/title>/, "Correct response"); }); }); @@ -51,10 +51,27 @@ test("Get resource from application.a (/i18n/i18n.properties) with correct chars } t.deepEqual(res.statusCode, 200, "Correct HTTP status code"); t.deepEqual(res.headers["content-type"], "text/plain; charset=ISO-8859-1", "Correct content type and charset"); - t.deepEqual(res.text, "showHelloButtonText=Say Hello!", "Correct response"); + t.deepEqual(Buffer.from(res.text, "latin1").toString(), "showHelloButtonText=Say Hello!", "Correct response"); }); }); +test("Get resource from application.a (/i18n/i18n_de.properties) with correct encoding 'ISO-8859-1'", (t) => { + return request.get("/i18n/i18n_de.properties") + .responseType("arraybuffer") + .then((res) => { + if (res.error) { + t.fail(res.error.text); + } + t.deepEqual(res.statusCode, 200, "Correct HTTP status code"); + t.deepEqual(res.headers["content-type"], "text/plain; charset=ISO-8859-1", + "Correct content type and charset"); + + t.deepEqual(res.body.toString("latin1"), "showHelloButtonText=Say ä!", "Correct response"); + // Because it took so long to figure this out I keep the below line. It is equivalent to the deepEqual above + // t.deepEqual(res.body.toString("latin1"), Buffer.from("showHelloButtonText=Say \u00e4!", "latin1").toString("latin1"), + // "Correct response"); + }); +}); test("Get resource from library.a (/resources/library/a/.library)", (t) => { return request.get("/resources/library/a/.library").then((res) => {