From 9ce888274c77e1b91161656e75e990faf9ef548f Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 10 Jun 2016 11:33:14 +0200 Subject: [PATCH 1/2] test: rebuild add-ons when their sources change The prerequisite for rebuilding was on the binding.gyp file but the actual sources. PR-URL: https://github.com/nodejs/node/pull/7262 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Trevor Norris --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index cf10346a211768..c44ed7934551d1 100644 --- a/Makefile +++ b/Makefile @@ -143,11 +143,15 @@ ADDONS_BINDING_GYPS := \ $(filter-out test/addons/??_*/binding.gyp, \ $(wildcard test/addons/*/binding.gyp)) +ADDONS_BINDING_SOURCES := \ + $(filter-out test/addons/??_*/*.cc, $(wildcard test/addons/*/*.cc)) \ + $(filter-out test/addons/??_*/*.h, $(wildcard test/addons/*/*.h)) \ + # Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale. # Depends on node-gyp package.json so that build-addons is (re)executed when # node-gyp is updated as part of an npm update. test/addons/.buildstamp: deps/npm/node_modules/node-gyp/package.json \ - $(ADDONS_BINDING_GYPS) \ + $(ADDONS_BINDING_GYPS) $(ADDONS_BINDING_SOURCES) \ deps/uv/include/*.h deps/v8/include/*.h \ src/node.h src/node_buffer.h src/node_object_wrap.h \ test/addons/.docbuildstamp From 6b48324363723dcd0e11444043b6c11f35d52ce2 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 10 Jun 2016 11:36:42 +0200 Subject: [PATCH 2/2] 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 54cc7212 ("buffer: introduce latin1 encoding term".) PR-URL: https://github.com/nodejs/node/pull/7262 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Trevor Norris --- Makefile | 2 +- src/node.cc | 1 + test/addons/parse-encoding/binding.cc | 36 ++++++++++++++++++++++++++ test/addons/parse-encoding/binding.gyp | 9 +++++++ test/addons/parse-encoding/test.js | 19 ++++++++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 test/addons/parse-encoding/binding.cc create mode 100644 test/addons/parse-encoding/binding.gyp create mode 100644 test/addons/parse-encoding/test.js diff --git a/Makefile b/Makefile index c44ed7934551d1..8d1796d14324dd 100644 --- a/Makefile +++ b/Makefile @@ -145,7 +145,7 @@ ADDONS_BINDING_GYPS := \ ADDONS_BINDING_SOURCES := \ $(filter-out test/addons/??_*/*.cc, $(wildcard test/addons/*/*.cc)) \ - $(filter-out test/addons/??_*/*.h, $(wildcard test/addons/*/*.h)) \ + $(filter-out test/addons/??_*/*.h, $(wildcard test/addons/*/*.h)) # Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale. # Depends on node-gyp package.json so that build-addons is (re)executed when diff --git a/src/node.cc b/src/node.cc index 0e042137ef6f2e..3ba079a41026a8 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1319,6 +1319,7 @@ enum encoding ParseEncoding(const char* encoding, if (strncmp(encoding + 2, "tin1", 4) == 0) return LATIN1; } + break; case 'b': // binary if (encoding[1] == 'i') { diff --git a/test/addons/parse-encoding/binding.cc b/test/addons/parse-encoding/binding.cc new file mode 100644 index 00000000000000..def91901f06d09 --- /dev/null +++ b/test/addons/parse-encoding/binding.cc @@ -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& args) { + const node::encoding encoding = + node::ParseEncoding(args.GetIsolate(), args[0], + static_cast(-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 target) { + NODE_SET_METHOD(target, "parseEncoding", ParseEncoding); +} + +} // anonymous namespace + +NODE_MODULE(binding, Initialize); diff --git a/test/addons/parse-encoding/binding.gyp b/test/addons/parse-encoding/binding.gyp new file mode 100644 index 00000000000000..7ede63d94a0d77 --- /dev/null +++ b/test/addons/parse-encoding/binding.gyp @@ -0,0 +1,9 @@ +{ + 'targets': [ + { + 'target_name': 'binding', + 'defines': [ 'V8_DEPRECATION_WARNINGS=1' ], + 'sources': [ 'binding.cc' ] + } + ] +} diff --git a/test/addons/parse-encoding/test.js b/test/addons/parse-encoding/test.js new file mode 100644 index 00000000000000..6c32374ca63307 --- /dev/null +++ b/test/addons/parse-encoding/test.js @@ -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');