summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2013-05-15 17:52:00 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2013-05-16 17:25:24 +0200
commitf59ab10a6415e7dce7a6c3b6e734c213298ec205 (patch)
tree0bb6c686383da23ac6a2c73b23218a6296801b4c
parent4cd643ee2d82d8bc2a4a7feab975b5c451ef692f (diff)
downloadnode-f59ab10a6415e7dce7a6c3b6e734c213298ec205.tar.gz
buffer, crypto: fix default encoding regression
The default encoding is 'buffer'. When the input is a string, treat it as 'binary'. Fixes the following assertion: node: ../src/string_bytes.cc:309: static size_t node::StringBytes::StorageSize(v8::Handle<v8::Value>, node::encoding): Assertion `0 && "buffer encoding specified but string provided"' failed. Introduced in 64fc34b2. Fixes #5482.
-rw-r--r--src/string_bytes.cc17
-rw-r--r--test/simple/test-buffer.js5
-rw-r--r--test/simple/test-crypto.js7
3 files changed, 16 insertions, 13 deletions
diff --git a/src/string_bytes.cc b/src/string_bytes.cc
index 5c90ae26f..90050dfcb 100644
--- a/src/string_bytes.cc
+++ b/src/string_bytes.cc
@@ -220,7 +220,8 @@ size_t StringBytes::Write(char* buf,
break;
}
- case BINARY: {
+ case BINARY:
+ case BUFFER: {
// TODO(isaacs): THIS IS AWFUL!!!
uint16_t* twobytebuf = new uint16_t[buflen];
@@ -248,10 +249,6 @@ size_t StringBytes::Write(char* buf,
break;
}
- case BUFFER:
- assert(0 && "buffer encoding specified, but string provided");
- break;
-
default:
assert(0 && "unknown encoding");
break;
@@ -277,6 +274,7 @@ size_t StringBytes::StorageSize(Handle<Value> val, enum encoding encoding) {
switch (encoding) {
case BINARY:
+ case BUFFER:
case ASCII:
data_size = str->Length();
break;
@@ -305,10 +303,6 @@ size_t StringBytes::StorageSize(Handle<Value> val, enum encoding encoding) {
data_size = str->Length() / 2;
break;
- case BUFFER:
- assert(0 && "buffer encoding specified but string provided");
- break;
-
default:
assert(0 && "unknown encoding");
break;
@@ -331,6 +325,7 @@ size_t StringBytes::Size(Handle<Value> val, enum encoding encoding) {
switch (encoding) {
case BINARY:
+ case BUFFER:
case ASCII:
data_size = str->Length();
break;
@@ -357,10 +352,6 @@ size_t StringBytes::Size(Handle<Value> val, enum encoding encoding) {
data_size = str->Length() / 2;
break;
- case BUFFER:
- assert(0 && "buffer encoding specified by string provided");
- break;
-
default:
assert(0 && "unknown encoding");
break;
diff --git a/test/simple/test-buffer.js b/test/simple/test-buffer.js
index cd9096de5..20a6bdba9 100644
--- a/test/simple/test-buffer.js
+++ b/test/simple/test-buffer.js
@@ -979,3 +979,8 @@ assert.throws(function() {
assert.equal(buf.slice(0, -i), s.slice(0, -i));
}
})();
+
+// Regression test for #5482: should throw but not assert in C++ land.
+assert.throws(function() {
+ Buffer('', 'buffer');
+}, TypeError);
diff --git a/test/simple/test-crypto.js b/test/simple/test-crypto.js
index e17f2d559..01487aca8 100644
--- a/test/simple/test-crypto.js
+++ b/test/simple/test-crypto.js
@@ -887,3 +887,10 @@ assert.throws(function() {
try { d.final('xxx') } catch (e) { /* Ignore. */ }
try { d.final('xxx') } catch (e) { /* Ignore. */ }
})();
+
+// Regression test for #5482: string to Cipher#update() should not assert.
+(function() {
+ var c = crypto.createCipher('aes192', '0123456789abcdef');
+ c.update('update');
+ c.final();
+})();