LibWeb: Calculate hidden password text using code-point count

This means that an `<input type=password>` will show the correct number
of *s in it when non-ASCII characters are entered.

We also don't need to perform text-transform on these as that doesn't
affect the output length, so I've moved it earlier.
This commit is contained in:
Sam Atkins 2024-11-14 18:06:16 +00:00 committed by Andreas Kling
commit c747b1c6b5
Notes: github-actions[bot] 2024-11-14 19:35:54 +00:00
3 changed files with 26 additions and 5 deletions

View file

@ -321,6 +321,11 @@ String const& TextNode::text_for_rendering() const
// NOTE: This collapses whitespace into a single ASCII space if the CSS white-space property tells us to.
void TextNode::compute_text_for_rendering()
{
if (dom_node().is_password_input()) {
m_text_for_rendering = MUST(String::repeated('*', dom_node().data().code_points().length()));
return;
}
bool collapse = [](CSS::WhiteSpace white_space) {
switch (white_space) {
case CSS::WhiteSpace::Normal:
@ -345,11 +350,6 @@ void TextNode::compute_text_for_rendering()
auto data_view = data.bytes_as_string_view();
if (dom_node().is_password_input()) {
m_text_for_rendering = MUST(String::repeated('*', data_view.length()));
return;
}
if (!collapse || data.is_empty()) {
m_text_for_rendering = data;
return;