Skip to content

Commit

Permalink
encoding normalization (reported in #23322)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Mar 29, 2017
1 parent b712ca9 commit 56d3f11
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/vs/base/node/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ const MINIMUM_THRESHOLD = 0.2; // TODO@Ben Decide how much this should be.
jschardet.Constants.MINIMUM_THRESHOLD = MINIMUM_THRESHOLD;

const IGNORE_ENCODINGS = ['ascii', 'utf-8', 'utf-16', 'utf-32'];
const MAPPED_ENCODINGS = {
'ibm866': 'cp866'
};

/**
* Guesses the encoding from buffer.
Expand All @@ -117,11 +120,14 @@ export function guessEncodingByBuffer(buffer: NodeBuffer): string {
return null;
}

return lowerCaseWithoutNonAlphaNumeric(guessed.encoding);
return toIconvLiteEncoding(guessed.encoding);
}

function lowerCaseWithoutNonAlphaNumeric(encodingName: string): string {
return encodingName.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
function toIconvLiteEncoding(encodingName: string): string {
const normalizedEncodingName = encodingName.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
const mapped = MAPPED_ENCODINGS[normalizedEncodingName];

return mapped || normalizedEncodingName;
}

/**
Expand Down

0 comments on commit 56d3f11

Please sign in to comment.