AK+LibJS+LibWeb: Recognize that our UTF-16 string is actually WTF-16

For the web, we allow a wobbly UTF-16 encoding (i.e. lonely surrogates
are permitted). Only in a few exceptional cases do we strictly require
valid UTF-16. As such, our `validate(AllowLonelySurrogates::Yes)` calls
will always succeed. It's a wasted effort to ever make such a check.

This patch eliminates such invocations. The validation methods will now
only check for strict UTF-16, and are only invoked when needed.
This commit is contained in:
Timothy Flynn
2025-08-08 16:32:26 -04:00
committed by Tim Flynn
parent 36c7302178
commit 8472e469f4
Notes: github-actions[bot] 2025-08-13 13:57:41 +00:00
20 changed files with 61 additions and 158 deletions

View File

@@ -807,7 +807,7 @@ void FormAssociatedTextControlElement::handle_insert(Utf16String const& data)
if (auto max_length = text_node->max_length(); max_length.has_value()) {
auto remaining_length = *max_length - text_node->length_in_utf16_code_units();
if (remaining_length < data.length_in_code_units())
data_for_insertion = Utf16String::from_utf16_without_validation(data.substring_view(0, remaining_length));
data_for_insertion = Utf16String::from_utf16(data.substring_view(0, remaining_length));
}
auto selection_start = this->selection_start();