From 5de78010701a9bf681f53de14e3a052d65663a3c Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Sun, 13 Jan 2019 12:40:04 +0100 Subject: [PATCH] codepage() defaults linux --- lib/util.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/util.js b/lib/util.js index 489a684..01cdccb 100644 --- a/lib/util.js +++ b/lib/util.js @@ -260,10 +260,18 @@ function getCodepage() { if (_linux || _darwin || _freebsd || _openbsd) { if (!codepage) { try { - const stdout = execSync('echo $LANG'); - const lines = stdout.toString().split('\r\n'); - const parts = lines[0].split('.'); - codepage = parts.length > 1 ? parts[1].trim() : ''; + const stdout = execSync('locale charmap'); + let lines = stdout.toString().split('\r\n'); + codepage = lines[0].trim(); + if (!codepage) { + const stdout = execSync('echo $LANG'); + lines = stdout.toString().split('\r\n'); + const parts = lines[0].split('.'); + codepage = parts.length > 1 ? parts[1].trim() : ''; + if (!codepage) { + codepage = 'UTF-8'; + } + } } catch (err) { codepage = 'UTF-8'; }