From 52dbb916c0414927c7afc8c22920fc67f0c500d7 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 30 Aug 2023 20:57:19 +0300 Subject: [PATCH] Specify file read encoding where possible --- server.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server.js b/server.js index 8db1df61a..f59f785ce 100644 --- a/server.js +++ b/server.js @@ -4227,7 +4227,7 @@ app.post('/readsecretstate', jsonParser, (_, response) => { } try { - const fileContents = fs.readFileSync(SECRETS_FILE); + const fileContents = fs.readFileSync(SECRETS_FILE, 'utf8'); const secrets = JSON.parse(fileContents); const state = {}; @@ -4286,7 +4286,7 @@ app.post('/viewsecrets', jsonParser, async (_, response) => { } try { - const fileContents = fs.readFileSync(SECRETS_FILE, 'utf8'); + const fileContents = fs.readFileSync(SECRETS_FILE, 'utf-8'); const secrets = JSON.parse(fileContents); return response.send(secrets); } catch (error) { @@ -4872,8 +4872,8 @@ function writeSecret(key, value) { writeFileAtomicSync(SECRETS_FILE, emptyFile, "utf-8"); } - const fileContents = fs.readFileSync(SECRETS_FILE); - const secrets = JSON.parse(fileContents.toString()); + const fileContents = fs.readFileSync(SECRETS_FILE, 'utf-8'); + const secrets = JSON.parse(fileContents); secrets[key] = value; writeFileAtomicSync(SECRETS_FILE, JSON.stringify(secrets), "utf-8"); } @@ -4883,8 +4883,8 @@ function readSecret(key) { return undefined; } - const fileContents = fs.readFileSync(SECRETS_FILE); - const secrets = JSON.parse(fileContents.toString()); + const fileContents = fs.readFileSync(SECRETS_FILE, 'utf-8'); + const secrets = JSON.parse(fileContents); return secrets[key]; }