forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: fix erroneous fallthrough in ParseEncoding()
A missing 'break' statement unintentionally allowed "linary" and "luffer" as alternatives for "binary" and "buffer". Regression introduced in commit 54cc721 ("buffer: introduce latin1 encoding term".) PR-URL: nodejs#7262 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
- Loading branch information
1 parent
a059aea
commit 7ba0f86
Showing
5 changed files
with
66 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "node.h" | ||
#include "v8.h" | ||
|
||
namespace { | ||
|
||
#define ENCODING_MAP(V) \ | ||
V(ASCII) \ | ||
V(BASE64) \ | ||
V(BUFFER) \ | ||
V(HEX) \ | ||
V(LATIN1) \ | ||
V(UCS2) \ | ||
V(UTF8) \ | ||
|
||
void ParseEncoding(const v8::FunctionCallbackInfo<v8::Value>& args) { | ||
const node::encoding encoding = | ||
node::ParseEncoding(args.GetIsolate(), args[0], | ||
static_cast<node::encoding>(-1)); | ||
const char* encoding_name = "UNKNOWN"; | ||
#define V(name) if (encoding == node::name) encoding_name = #name; | ||
ENCODING_MAP(V) | ||
#undef V | ||
auto encoding_string = | ||
v8::String::NewFromUtf8(args.GetIsolate(), encoding_name, | ||
v8::NewStringType::kNormal) | ||
.ToLocalChecked(); | ||
args.GetReturnValue().Set(encoding_string); | ||
} | ||
|
||
void Initialize(v8::Local<v8::Object> target) { | ||
NODE_SET_METHOD(target, "parseEncoding", ParseEncoding); | ||
} | ||
|
||
} // anonymous namespace | ||
|
||
NODE_MODULE(binding, Initialize); |
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,9 @@ | ||
{ | ||
'targets': [ | ||
{ | ||
'target_name': 'binding', | ||
'defines': [ 'V8_DEPRECATION_WARNINGS=1' ], | ||
'sources': [ 'binding.cc' ] | ||
} | ||
] | ||
} |
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,19 @@ | ||
'use strict'; | ||
|
||
require('../../common'); | ||
const assert = require('assert'); | ||
const { parseEncoding } = require('./build/Release/binding'); | ||
|
||
assert.strictEqual(parseEncoding(''), 'UNKNOWN'); | ||
|
||
assert.strictEqual(parseEncoding('ascii'), 'ASCII'); | ||
assert.strictEqual(parseEncoding('base64'), 'BASE64'); | ||
assert.strictEqual(parseEncoding('binary'), 'LATIN1'); | ||
assert.strictEqual(parseEncoding('buffer'), 'BUFFER'); | ||
assert.strictEqual(parseEncoding('hex'), 'HEX'); | ||
assert.strictEqual(parseEncoding('latin1'), 'LATIN1'); | ||
assert.strictEqual(parseEncoding('ucs2'), 'UCS2'); | ||
assert.strictEqual(parseEncoding('utf8'), 'UTF8'); | ||
|
||
assert.strictEqual(parseEncoding('linary'), 'UNKNOWN'); | ||
assert.strictEqual(parseEncoding('luffer'), 'UNKNOWN'); |