From 3ca8659bba16d07c7a0b504dc09ac27b704eccef Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 1 Mar 2017 22:44:30 +0000 Subject: [PATCH] Fix bad encoding of static files. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3395 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/terminal.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/core/terminal.js b/core/terminal.js index 14dc73602..00946ca5a 100644 --- a/core/terminal.js +++ b/core/terminal.js @@ -237,18 +237,21 @@ async function handler(request, response, packageOwner, packageName, uri) { for (var i in kStaticFiles) { if (uri === kStaticFiles[i].uri) { found = true; - var data = new TextDecoder("UTF-8").decode(File.readFile("core/" + kStaticFiles[i].path)); - if (kStaticFiles[i].uri == "") { - if (gGlobalSettings && gGlobalSettings['google-signin-client_id']) { - data = data.replace("", ` + var data = File.readFile("core/" + kStaticFiles[i].path); + if (kStaticFiles[i].type.indexOf("text/") == 0) { + data = new TextDecoder("UTF-8").decode(data); + if (kStaticFiles[i].uri == "") { + if (gGlobalSettings && gGlobalSettings['google-signin-client_id']) { + data = data.replace("", ` `); + } + data = data.replace("$(VIEW_SOURCE)", "/~" + packageOwner + "/" + packageName + "/view"); } - data = data.replace("$(VIEW_SOURCE)", "/~" + packageOwner + "/" + packageName + "/view"); + data = new TextEncoder("UTF-8").encode(data); } - var raw = new TextEncoder("UTF-8").encode(data); - response.writeHead(200, {"Content-Type": kStaticFiles[i].type, "Content-Length": raw.length}); - response.end(raw); + response.writeHead(200, {"Content-Type": kStaticFiles[i].type, "Content-Length": data.length}); + response.end(data); break; } }