Skip to content

Commit

Permalink
src: remove NODE_INVALID_UTF8 environment variable
Browse files Browse the repository at this point in the history
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: #1042
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
bnoordhuis committed Mar 5, 2015
1 parent 826cde8 commit 364cc7e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
8 changes: 0 additions & 8 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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".
Expand Down
7 changes: 4 additions & 3 deletions src/string_bytes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,9 @@ size_t StringBytes::Write(Isolate* isolate,
Local<String> str = val.As<String>();
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:
Expand All @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions src/string_bytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

namespace node {

extern int WRITE_UTF8_FLAGS;

class StringBytes {
public:
class InlineDecoder {
Expand Down
9 changes: 3 additions & 6 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ Utf8Value::Utf8Value(v8::Isolate* isolate, v8::Handle<v8::Value> 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<char*>(str);
Expand Down

0 comments on commit 364cc7e

Please sign in to comment.