| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6fc20c5 commit a550ddb
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -995,9 +995,9 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { | |||
| 995 | 995 | ||
| 996 | 996 | const char* haystack = ts_obj_data; | |
| 997 | 997 | const size_t haystack_length = ts_obj_length; | |
| 998 | - // Extended latin-1 characters are 2 bytes in Utf8. | ||
| 998 | + | ||
| 999 | 999 | const size_t needle_length = | |
| 1000 | - enc == BINARY ? needle->Length() : needle->Utf8Length(); | ||
| 1000 | + StringBytes::Size(args.GetIsolate(), needle, enc); | ||
| 1001 | 1001 | ||
| 1002 | 1002 | if (needle_length == 0 || haystack_length == 0) { | |
| 1003 | 1003 | return args.GetReturnValue().Set(-1); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -222,6 +222,12 @@ var allCharsBufferUcs2 = Buffer.from(allCharsString, 'ucs2'); | |||
| 222 | 222 | assert.equal(-1, allCharsBufferUtf8.indexOf('notfound')); | |
| 223 | 223 | assert.equal(-1, allCharsBufferUcs2.indexOf('notfound')); | |
| 224 | 224 | ||
| 225 | + // Needle is longer than haystack, but only because it's encoded as UTF-16 | ||
| 226 | + assert.strictEqual(Buffer.from('aaaa').indexOf('a'.repeat(4), 'ucs2'), -1); | ||
| 227 | + | ||
| 228 | + assert.strictEqual(Buffer.from('aaaa').indexOf('a'.repeat(4), 'utf8'), 0); | ||
| 229 | + assert.strictEqual(Buffer.from('aaaa').indexOf('你好', 'ucs2'), -1); | ||
| 230 | + | ||
| 225 | 231 | { | |
| 226 | 232 | // Find substrings in Utf8. | |
| 227 | 233 | const lengths = [1, 3, 15]; // Single char, simple and complex. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments