| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7240ad4 commit 54cd2e1
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -849,7 +849,9 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) { | |||
| 849 | 849 | Local<String> needle = args[1].As<String>(); | |
| 850 | 850 | const char* haystack = ts_obj_data; | |
| 851 | 851 | const size_t haystack_length = ts_obj_length; | |
| 852 | - const size_t needle_length = needle->Utf8Length(); | ||
| 852 | + // Extended latin-1 characters are 2 bytes in Utf8. | ||
| 853 | + const size_t needle_length = | ||
| 854 | + enc == BINARY ? needle->Length() : needle->Utf8Length(); | ||
| 853 | 855 | ||
| 854 | 856 | ||
| 855 | 857 | if (needle_length == 0 || haystack_length == 0) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -109,6 +109,15 @@ assert.equal( | |||
| 109 | 109 | assert.equal( | |
| 110 | 110 | Buffer(b.toString('binary'), 'binary') | |
| 111 | 111 | .indexOf(Buffer('d', 'binary'), 0, 'binary'), 3); | |
| 112 | + assert.equal( | ||
| 113 | + Buffer('aa\u00e8aa', 'binary') | ||
| 114 | + .indexOf('\u00e8', 'binary'), 2); | ||
| 115 | + assert.equal( | ||
| 116 | + Buffer('\u00e8', 'binary') | ||
| 117 | + .indexOf('\u00e8', 'binary'), 0); | ||
| 118 | + assert.equal( | ||
| 119 | + Buffer('\u00e8', 'binary') | ||
| 120 | + .indexOf(Buffer('\u00e8', 'binary'), 'binary'), 0); | ||
| 112 | 121 | ||
| 113 | 122 | ||
| 114 | 123 | // test optional offset with passed encoding | |
| Back | FazBrowse Home | New Git URL |
0 commit comments