-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
buffer,string_decoder: consolidate encoding validation logic
Buffer.isEncoding and string_decoder.normalizeEncoding shared quite a bit of logic. This moves the primary logic into internal/util. The userland modules that monkey patch Buffer.isEncoding should still work.
- Loading branch information
Showing
5 changed files
with
88 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const util = require('internal/util'); | ||
|
||
const tests = [ | ||
['', 'utf8'], | ||
['utf8', 'utf8'], | ||
['utf-8', 'utf8'], | ||
['UTF-8', 'utf8'], | ||
['UTF8', 'utf8'], | ||
['Utf8', 'utf8'], | ||
['uTf-8', 'utf8'], | ||
['utF-8', 'utf8'], | ||
['ucs2', 'utf16le'], | ||
['UCS2', 'utf16le'], | ||
['utf16le', 'utf16le'], | ||
['utf-16le', 'utf16le'], | ||
['UTF-16LE', 'utf16le'], | ||
['UTF16LE', 'utf16le'], | ||
['binary', 'latin1'], | ||
['BINARY', 'latin1'], | ||
['latin1', 'latin1'], | ||
['base64', 'base64'], | ||
['BASE64', 'base64'], | ||
['hex', 'hex'], | ||
['HEX', 'hex'], | ||
['foo', undefined], | ||
[1, undefined], | ||
[false, 'utf8'], | ||
[undefined, 'utf8'], | ||
[[], undefined], | ||
]; | ||
|
||
tests.forEach((i) => { | ||
assert.strictEqual(util.normalizeEncoding(i[0]), i[1]); | ||
}); |