Skip to content

Commit 78bfc7e

Browse files
authored
Fix passing of strings with nulls from Py to JS (#24)
1 parent 1a6d3a8 commit 78bfc7e

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/v8_py_frontend/binary_value.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,10 @@ auto BinaryValueFactory::ToValue(v8::Local<v8::Context> context,
314314
}
315315

316316
if (bv_ptr->type == type_str_utf8) {
317-
return v8::String::NewFromUtf8(isolate, bv_ptr->bytes).ToLocalChecked();
317+
return v8::String::NewFromUtf8(isolate, bv_ptr->bytes,
318+
v8::NewStringType::kNormal,
319+
static_cast<int>(bv_ptr->len))
320+
.ToLocalChecked();
318321
}
319322

320323
// Unknown type!

src/v8_py_frontend/binary_value.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ struct BinaryValue {
6868
union {
6969
char* backing_store_ptr;
7070
gsl::owner<char*> bytes;
71-
gsl::owner<v8::Persistent<v8::Value>*> value_ptr;
7271
int64_t int_val;
7372
double double_val;
7473
};

tests/test_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def test_str():
5050
v = Validator()
5151
v.validate("'a string'")
5252
v.validate("'a ' + 'string'")
53+
v.validate("string with null \0 byte")
5354

5455

5556
def test_unicode():

0 commit comments

Comments
 (0)