From b010c8716498dca398e61c388859fea92296feb3 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Wed, 2 Mar 2016 14:43:39 +0300 Subject: crypto, string_bytes: treat `buffer` str as `utf8` Do not treat crypto inputs as `binary` strings, convert them to Buffers using `new Buffer(..., 'utf8')`, or using newly updated StringBytes APIs. PR-URL: https://github.com/nodejs/node/pull/5522 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- src/string_bytes.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/string_bytes.cc') diff --git a/src/string_bytes.cc b/src/string_bytes.cc index a916caf75e..d9ca6e565e 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -368,7 +368,6 @@ size_t StringBytes::Write(Isolate* isolate, switch (encoding) { case ASCII: case BINARY: - case BUFFER: if (is_extern && str->IsOneByte()) { memcpy(buf, data, nbytes); } else { @@ -379,6 +378,7 @@ size_t StringBytes::Write(Isolate* isolate, *chars_written = nbytes; break; + case BUFFER: case UTF8: nbytes = str->WriteUtf8(buf, buflen, chars_written, flags); break; @@ -480,11 +480,11 @@ size_t StringBytes::StorageSize(Isolate* isolate, switch (encoding) { case BINARY: - case BUFFER: case ASCII: data_size = str->Length(); break; + case BUFFER: case UTF8: // A single UCS2 codepoint never takes up more than 3 utf8 bytes. // It is an exercise for the caller to decide when a string is @@ -532,11 +532,11 @@ size_t StringBytes::Size(Isolate* isolate, switch (encoding) { case BINARY: - case BUFFER: case ASCII: data_size = str->Length(); break; + case BUFFER: case UTF8: data_size = str->Utf8Length(); break; -- cgit v1.2.3