File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ( ) {
You can’t perform that action at this time.
0 commit comments