mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
LibWeb/HTML: Only use maxlength <input> attribute when applicable
This commit is contained in:
parent
5aeae5e583
commit
7b637b1eee
Notes:
github-actions[bot]
2025-01-15 10:42:38 +00:00
Author: https://github.com/shannonbooth Commit: https://github.com/LadybirdBrowser/ladybird/commit/7b637b1eeee Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3260 Reviewed-by: https://github.com/gmta ✅
3 changed files with 44 additions and 2 deletions
|
@ -2,7 +2,7 @@
|
|||
* Copyright (c) 2018-2023, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2022, Adam Hodgen <ant1441@gmail.com>
|
||||
* Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
|
||||
* Copyright (c) 2023-2024, Shannon Booth <shannon@serenityos.org>
|
||||
* Copyright (c) 2023-2025, Shannon Booth <shannon@serenityos.org>
|
||||
* Copyright (c) 2023, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com>
|
||||
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
|
||||
* Copyright (c) 2024, Fernando Kiotheka <fer@k6a.dev>
|
||||
|
@ -721,10 +721,27 @@ static bool is_allowed_to_be_readonly(HTML::HTMLInputElement::TypeAttributeState
|
|||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#the-input-element:attr-input-maxlength-3
|
||||
static bool is_applicable_for_maxlength_attribute(HTML::HTMLInputElement::TypeAttributeState state)
|
||||
{
|
||||
switch (state) {
|
||||
case HTML::HTMLInputElement::TypeAttributeState::Text:
|
||||
case HTML::HTMLInputElement::TypeAttributeState::Search:
|
||||
case HTML::HTMLInputElement::TypeAttributeState::Telephone:
|
||||
case HTML::HTMLInputElement::TypeAttributeState::URL:
|
||||
case HTML::HTMLInputElement::TypeAttributeState::Email:
|
||||
case HTML::HTMLInputElement::TypeAttributeState::Password:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#attr-input-maxlength
|
||||
void HTMLInputElement::handle_maxlength_attribute()
|
||||
{
|
||||
if (m_text_node) {
|
||||
// The maxlength attribute, when it applies, is a form control maxlength attribute.
|
||||
if (m_text_node && is_applicable_for_maxlength_attribute(type_state())) {
|
||||
auto max_length = this->max_length();
|
||||
if (max_length >= 0) {
|
||||
m_text_node->set_max_length(max_length);
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
Harness status: OK
|
||||
|
||||
Found 1 tests
|
||||
|
||||
1 Pass
|
||||
Pass maxlength doesn't apply to input type=number
|
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<title>input type=number maxlength</title>
|
||||
<script src="../../../../resources/testharness.js"></script>
|
||||
<script src="../../../../resources/testharnessreport.js"></script>
|
||||
<script src="../../../../resources/testdriver.js"></script>
|
||||
<script src="../../../../resources/testdriver-vendor.js"></script>
|
||||
|
||||
<input type="number" maxlength="1">
|
||||
|
||||
<script>
|
||||
async_test(t => {
|
||||
let elem = document.getElementsByTagName("input")[0];
|
||||
test_driver.send_keys(elem, "1234")
|
||||
.then(t.step_func(() => {
|
||||
assert_equals(elem.value, "1234");
|
||||
t.done();
|
||||
}));
|
||||
}, "maxlength doesn't apply to input type=number");
|
||||
</script>
|
Loading…
Reference in a new issue