Skip to content

Commit 364cc7e

Browse files
committed
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: #1042 Reviewed-By: Trevor Norris <[email protected]>
1 parent 826cde8 commit 364cc7e

File tree

4 files changed

+7
-19
lines changed

4 files changed

+7
-19
lines changed

src/node.cc

-8
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ static uv_async_t dispatch_debug_messages_async;
139139

140140
static Isolate* node_isolate = nullptr;
141141

142-
int WRITE_UTF8_FLAGS = v8::String::HINT_MANY_WRITES_EXPECTED |
143-
v8::String::NO_NULL_TERMINATION;
144-
145142
class ArrayBufferAllocator : public ArrayBuffer::Allocator {
146143
public:
147144
// Impose an upper limit to avoid out of memory errors that bring down
@@ -3819,11 +3816,6 @@ static void StartNodeInstance(void* arg) {
38193816
int Start(int argc, char** argv) {
38203817
PlatformInit();
38213818

3822-
const char* replace_invalid = secure_getenv("NODE_INVALID_UTF8");
3823-
3824-
if (replace_invalid == nullptr)
3825-
WRITE_UTF8_FLAGS |= String::REPLACE_INVALID_UTF8;
3826-
38273819
CHECK_GT(argc, 0);
38283820

38293821
// Hack around with the argv pointer. Used for process.title = "blah".

src/string_bytes.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,9 @@ size_t StringBytes::Write(Isolate* isolate,
287287
Local<String> str = val.As<String>();
288288
len = len < buflen ? len : buflen;
289289

290-
int flags = String::NO_NULL_TERMINATION |
291-
String::HINT_MANY_WRITES_EXPECTED;
290+
int flags = String::HINT_MANY_WRITES_EXPECTED |
291+
String::NO_NULL_TERMINATION |
292+
String::REPLACE_INVALID_UTF8;
292293

293294
switch (encoding) {
294295
case ASCII:
@@ -311,7 +312,7 @@ size_t StringBytes::Write(Isolate* isolate,
311312
// well?
312313
memcpy(buf, data, len);
313314
else
314-
len = str->WriteUtf8(buf, buflen, chars_written, WRITE_UTF8_FLAGS);
315+
len = str->WriteUtf8(buf, buflen, chars_written, flags);
315316
break;
316317

317318
case UCS2:

src/string_bytes.h

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
namespace node {
1212

13-
extern int WRITE_UTF8_FLAGS;
14-
1513
class StringBytes {
1614
public:
1715
class InlineDecoder {

src/util.cc

+3-6
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ Utf8Value::Utf8Value(v8::Isolate* isolate, v8::Handle<v8::Value> value)
2323
str = str_st_;
2424
CHECK_NE(str, NULL);
2525

26-
int flags = WRITE_UTF8_FLAGS;
27-
28-
length_ = val_->WriteUtf8(str,
29-
len,
30-
0,
31-
flags);
26+
const int flags =
27+
v8::String::NO_NULL_TERMINATION | v8::String::REPLACE_INVALID_UTF8;
28+
length_ = val_->WriteUtf8(str, len, 0, flags);
3229
str[length_] = '\0';
3330

3431
str_ = reinterpret_cast<char*>(str);

0 commit comments

Comments
 (0)