Skip to content

Commit ddfca30

Browse files
author
Benjamin Pasero
committed
encoding - still ignore 'ascii'
1 parent b66599b commit ddfca30

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/vs/base/node/encoding.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,17 @@ async function guessEncodingByBuffer(buffer: Buffer): Promise<string | null> {
210210
return null;
211211
}
212212

213+
// Ignore 'ascii' as guessed encoding because that
214+
// is almost never what we want, rather fallback
215+
// to the configured encoding then. Otherwise,
216+
// opening a ascii-only file with auto guessing
217+
// enabled will put the file into 'ascii' mode
218+
// and thus typing any special characters is
219+
// not possible anymore.
220+
if (guessed.encoding.toLowerCase() === 'ascii') {
221+
return null;
222+
}
223+
213224
return toIconvLiteEncoding(guessed.encoding);
214225
}
215226

src/vs/base/test/node/encoding/encoding.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ suite('Encoding', () => {
200200
const file = getPathFromAmdModule(require, './fixtures/some_ansi.css');
201201
const buffer = await readExactlyByFile(file, 512 * 8);
202202
const mimes = await encoding.detectEncodingFromBuffer(buffer, true);
203-
assert.equal(mimes.encoding, 'ascii');
203+
assert.equal(mimes.encoding, null);
204204
});
205205

206206
test('autoGuessEncoding (ShiftJIS)', async function () {

0 commit comments

Comments
 (0)