Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(746)

Unified Diff: test/cctest/test-strings.cc

Issue 6524031: Terminate on \0 in data passed to String::New() (Closed)
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/heap.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-strings.cc
diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc
index 3f02b32b8c43331889f72ee4f95941c17b611bf1..51c57629b66d1d34d3dae6f1e51639b6c8f96e4d 100644
--- a/test/cctest/test-strings.cc
+++ b/test/cctest/test-strings.cc
@@ -103,7 +103,7 @@ static void InitializeBuildingBlocks(
case 1: {
char buf[2000];
for (int j = 0; j < len; j++) {
- buf[j] = gen() % 128;
+ buf[j] = gen() % 127 + 1;
}
building_blocks[i] =
Factory::NewStringFromAscii(Vector<const char>(buf, len));
@@ -127,7 +127,7 @@ static void InitializeBuildingBlocks(
case 3: {
char* buf = NewArray<char>(len);
for (int j = 0; j < len; j++) {
- buf[j] = gen() % 128;
+ buf[j] = gen() % 127 + 1;
}
building_blocks[i] =
Factory::NewStringFromAscii(Vector<const char>(buf, len));
@@ -300,6 +300,22 @@ TEST(DeepAscii) {
DeleteArray<char>(foo);
}
+TEST(TrailingNulls) {
+ InitializeVM();
+ v8::HandleScope handle_scope;
+
+ const char* hello_ascii = "Hello!\0\0\0\0\0";
+ v8::Handle<v8::String> ascii = v8::String::New(hello_ascii, 11);
+ CHECK_EQ(6, ascii->Utf8Length());
+
+ // hello in hebrew
+ const uint8_t hello_utf[] = { 0xd7, 0xa9, 0xd7, 0x9c,
+ 0xd7, 0x95, 0xd7, 0x9d,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00 };
+ v8::Handle<v8::String> utf = v8::String::New((char *)hello_utf, 16);
+ CHECK_EQ(8, utf->Utf8Length());
+}
TEST(Utf8Conversion) {
// Smoke test for converting strings to utf-8.
« no previous file with comments | « src/heap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698