Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: convert BE-utf16-string to LE before search #3295

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -842,11 +842,27 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
return args.GetReturnValue().Set(-1);
}

result = SearchString(reinterpret_cast<const uint16_t*>(haystack),
haystack_length / 2,
reinterpret_cast<const uint16_t*>(*needle_value),
needle_value.length(),
offset / 2);
if (IsBigEndian()) {
StringBytes::InlineDecoder decoder;
decoder.Decode(Environment::GetCurrent(args), needle, args[3], UCS2);
const uint16_t* decoded_string =
reinterpret_cast<const uint16_t*>(decoder.out());

if (decoded_string == nullptr)
return args.GetReturnValue().Set(-1);

result = SearchString(reinterpret_cast<const uint16_t*>(haystack),
haystack_length / 2,
decoded_string,
decoder.size() / 2,
offset / 2);
} else {
result = SearchString(reinterpret_cast<const uint16_t*>(haystack),
haystack_length / 2,
reinterpret_cast<const uint16_t*>(*needle_value),
needle_value.length(),
offset / 2);
}
result *= 2;
} else if (enc == UTF8) {
String::Utf8Value needle_value(needle);
Expand Down