From 364cc7e08a5d4b74891362f837ff9c34844c3d35 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 3 Mar 2015 15:09:58 +0100 Subject: [PATCH] src: remove NODE_INVALID_UTF8 environment variable Introduced in joyent/node v0.10 as a backwards compatibility measure. It's an ugly hack and allowing invalid UTF-8 is not a good idea in the first place, remove it. PR-URL: https://github.com/iojs/io.js/pull/1042 Reviewed-By: Trevor Norris --- src/node.cc | 8 -------- src/string_bytes.cc | 7 ++++--- src/string_bytes.h | 2 -- src/util.cc | 9 +++------ 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/node.cc b/src/node.cc index 1bee586033..22c4a9b154 100644 --- a/src/node.cc +++ b/src/node.cc @@ -139,9 +139,6 @@ static uv_async_t dispatch_debug_messages_async; static Isolate* node_isolate = nullptr; -int WRITE_UTF8_FLAGS = v8::String::HINT_MANY_WRITES_EXPECTED | - v8::String::NO_NULL_TERMINATION; - class ArrayBufferAllocator : public ArrayBuffer::Allocator { public: // Impose an upper limit to avoid out of memory errors that bring down @@ -3819,11 +3816,6 @@ static void StartNodeInstance(void* arg) { int Start(int argc, char** argv) { PlatformInit(); - const char* replace_invalid = secure_getenv("NODE_INVALID_UTF8"); - - if (replace_invalid == nullptr) - WRITE_UTF8_FLAGS |= String::REPLACE_INVALID_UTF8; - CHECK_GT(argc, 0); // Hack around with the argv pointer. Used for process.title = "blah". diff --git a/src/string_bytes.cc b/src/string_bytes.cc index c828363da6..4a91f25048 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -287,8 +287,9 @@ size_t StringBytes::Write(Isolate* isolate, Local str = val.As(); len = len < buflen ? len : buflen; - int flags = String::NO_NULL_TERMINATION | - String::HINT_MANY_WRITES_EXPECTED; + int flags = String::HINT_MANY_WRITES_EXPECTED | + String::NO_NULL_TERMINATION | + String::REPLACE_INVALID_UTF8; switch (encoding) { case ASCII: @@ -311,7 +312,7 @@ size_t StringBytes::Write(Isolate* isolate, // well? memcpy(buf, data, len); else - len = str->WriteUtf8(buf, buflen, chars_written, WRITE_UTF8_FLAGS); + len = str->WriteUtf8(buf, buflen, chars_written, flags); break; case UCS2: diff --git a/src/string_bytes.h b/src/string_bytes.h index 424d9245aa..2fcfedaa09 100644 --- a/src/string_bytes.h +++ b/src/string_bytes.h @@ -10,8 +10,6 @@ namespace node { -extern int WRITE_UTF8_FLAGS; - class StringBytes { public: class InlineDecoder { diff --git a/src/util.cc b/src/util.cc index 1c57a976e1..1e8d801dba 100644 --- a/src/util.cc +++ b/src/util.cc @@ -23,12 +23,9 @@ Utf8Value::Utf8Value(v8::Isolate* isolate, v8::Handle value) str = str_st_; CHECK_NE(str, NULL); - int flags = WRITE_UTF8_FLAGS; - - length_ = val_->WriteUtf8(str, - len, - 0, - flags); + const int flags = + v8::String::NO_NULL_TERMINATION | v8::String::REPLACE_INVALID_UTF8; + length_ = val_->WriteUtf8(str, len, 0, flags); str[length_] = '\0'; str_ = reinterpret_cast(str);