mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-22 17:31:58 -05:00
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. (cherry picked from commit c747b1c6b56156b5797fad0d8d95164f415c8b25; amended to slightly adjust some BlockContainer and PaintableWithLines widths, since serenity does not use harfbuzz for text shaping)
This commit is contained in:
parent
59b862d978
commit
f63a15665d
3 changed files with 26 additions and 5 deletions
19
Tests/LibWeb/Layout/expected/unicode-password-input.txt
Normal file
19
Tests/LibWeb/Layout/expected/unicode-password-input.txt
Normal file
|
@ -0,0 +1,19 @@
|
|||
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||
BlockContainer <html> at (0,0) content-size 800x37 [BFC] children: not-inline
|
||||
BlockContainer <body> at (8,8) content-size 784x21 children: inline
|
||||
frag 0 from BlockContainer start: 0, length: 0, rect: [9,9 191.875x19] baseline: 14.296875
|
||||
BlockContainer <input> at (9,9) content-size 191.875x19 inline-block [BFC] children: not-inline
|
||||
Box <div> at (11,10) content-size 187.875x17 flex-container(row) [FFC] children: not-inline
|
||||
BlockContainer <div> at (11,10) content-size 187.875x17 flex-item [BFC] children: inline
|
||||
frag 0 from TextNode start: 0, length: 14, rect: [11,10 111.125x17] baseline: 13.296875
|
||||
"**************"
|
||||
TextNode <#text>
|
||||
TextNode <#text>
|
||||
|
||||
ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x37]
|
||||
PaintableWithLines (BlockContainer<BODY>) [8,8 784x21]
|
||||
PaintableWithLines (BlockContainer<INPUT>) [8,8 193.875x21]
|
||||
PaintableBox (Box<DIV>) [9,9 191.875x19]
|
||||
PaintableWithLines (BlockContainer<DIV>) [11,10 187.875x17]
|
||||
TextPaintable (TextNode<#text>)
|
2
Tests/LibWeb/Layout/input/unicode-password-input.html
Normal file
2
Tests/LibWeb/Layout/input/unicode-password-input.html
Normal file
|
@ -0,0 +1,2 @@
|
|||
<!DOCTYPE html>
|
||||
<input type="password" value="こんにちは、友達のみなさん!">
|
|
@ -316,6 +316,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:
|
||||
|
@ -336,11 +341,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;
|
||||
|
|
Loading…
Reference in a new issue