input type='number' with maxlength attribute is enforced on firefox and not chrome and safari
Categories
(Core :: Layout: Form Controls, defect)
Tracking
()
Tracking | Status | |
---|---|---|
firefox-esr68 | --- | unaffected |
firefox73 | --- | unaffected |
firefox74 | + | verified |
firefox75 | --- | verified |
People
(Reporter: pere.jobs, Assigned: emilio)
References
(Regression)
Details
(Keywords: regression)
Attachments
(3 files)
(deleted),
text/x-phabricator-request
|
pascalc
:
approval-mozilla-beta+
|
Details |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
pascalc
:
approval-mozilla-beta+
|
Details |
User Agent: Mozilla/5.0 (Android 9; Mobile; rv:75.0) Gecko/75.0 Firefox/75.0
Steps to reproduce:
Install Firefox for Android Nightly 200214 08:03 (Build #2015722947) 32.0.0, 9ff30b22e
GV: 75.0a1-20200213035745
Go to https://reg-game.netlify.com/
Click "play alone"
Try to type "16" in a cell
Actual results:
A single "1" appears in the cell
Expected results:
"16" appears in the cell
Comment 1•5 years ago
|
||
This reproduces on desktop Firefox. Seems like a poorly coded website.
Reporter | ||
Comment 2•5 years ago
|
||
I cannot reproduce it on Firefox desktop nor Firefox for Android stable, or any other browser. It seems like a regression.
Comment 3•5 years ago
|
||
well…
<input
class="numbox svelte-3p3mko"
pattern="1|2|3|4|5|6|7|8|9|10|11|12|13|14|15"
title="Values you can play here: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15."
type="number"
max="16" min="1"
step="1"
maxlength="1">
it's written on the tin.
maxlength="1"
The issue is why safari tech preview and chrome canary accepts to get a number even with maxlength="1"
This was fixed 17 years ago? by boris
https://bugzilla.mozilla.org/show_bug.cgi?id=190425
What is the spec saying https://html.spec.whatwg.org/multipage/input.html#attr-input-maxlength
The maxlength attribute, when it applies, is a form control maxlength attribute.
Following https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-maxlength
Constraint validation: If an element has a maximum allowed value length, its dirty value flag is true, its value was last changed by a user edit (as opposed to a change made by a script), and the JavaScript string length of the element's API value is greater than the element's maximum allowed value length, then the element is suffering from being too long.
User agents may prevent the user from causing the element's API value to be set to a value whose JavaScript string length is greater than the element's maximum allowed value length.
It doesn't seem a hard constraint, but
results for type='number'
- enter into the url bar
data:text/html,<input type='number' maxlength='2'/>
- type 123
Results in different browsers
- firefox: 12 (75.0a1 (2020-02-18) (64-bit))
- chrome: 123 (Version 82.0.4062.4 (Build officiel) canary (64 bits))
- safari: 123 (Release 100 (Safari 13.2, WebKit 15610.1.2.1))
results for type='text'
data:text/html,<input type='text' maxlength='2'/>
Results in different browsers
- firefox: 12 (75.0a1 (2020-02-18) (64-bit))
- chrome: 12 (Version 82.0.4062.4 (Build officiel) canary (64 bits))
- safari: 12 (Release 100 (Safari 13.2, WebKit 15610.1.2.1))
So that looks like a bug in Chrome and Safari, more than Firefox. Maybe there are bugs already opened there.
slightly related but more about the type invalid type being entered, so probably a new issue to create on chromium
https://bugs.chromium.org/p/chromium/issues/detail?id=365196
let's see webkit. no issue related to this issue.
https://bugs.webkit.org/buglist.cgi?bug_status=__open__&content=maxlength&no_redirect=1&order=Importance&product=WebKit&query_format=specific
that would be a good addition to web platform tests too.
Updated•5 years ago
|
Comment 4•5 years ago
|
||
Comment 5•5 years ago
|
||
ah interesting I had missed this
tkent commented on the chromium issue.
https://bugs.chromium.org/p/chromium/issues/detail?id=1054251#c2
https://html.spec.whatwg.org/multipage/input.html#number-state-(type=number)
The following content attributes must not be specified and do not apply to the element: accept, alt, checked, dirname, formaction, formenctype, formmethod, formnovalidate, formtarget, height, maxlength, minlength, multiple, pattern, size, src, and width.
So we might have an issue.
Updated•5 years ago
|
Reporter | ||
Comment 6•5 years ago
|
||
Oh! I wouldn't have reported this bug if I had noted the maxlength=1
in the first place ><
But I'm glad it ended up not being a waste of time, since it seems to be a real spec-conformance bug.
What is interesting is that the behavior changed recently:
- firefox 75.0a1 : affected
- firefox 73.0.1 : not affected
Comment 7•5 years ago
|
||
Updated•5 years ago
|
Comment 8•5 years ago
|
||
[Tracking Requested - why for this release]:
web compat regression
Emilio, looks like bug 981248 broke this. We just about haven't shipped this yet - can you take a look?
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Comment 9•5 years ago
|
||
Ophir LOJKINE, thank you very much for reporting this!
Comment 10•5 years ago
|
||
I suspect we want to change TextControlState::GetMaxLength
and nsTextControlFrame::GetMaxLength
to return -1 for number inputs. I wonder whether we can just move this into the InputType thing and then use the fact that number inputs don't use the text control input type...
Assignee | ||
Updated•5 years ago
|
Assignee | ||
Comment 11•5 years ago
|
||
Depends on D63460
Reporter | ||
Comment 12•5 years ago
|
||
The reference (https://html.spec.whatwg.org/multipage/input.html) has a table summarizing which input types maxlength applies to: Text, Search, URL, Telephone, E-mail, Password. All the other types (not only "Number") are unaffected by maxlength. It may be worth checking if this bug also affects other input types.
Assignee | ||
Comment 13•5 years ago
|
||
Yeah, it doesn't because the others don't use the text-editing code... Maybe I could make it more explicit and check for them anyway, or assert it's not called for those types...
Reporter | ||
Comment 14•5 years ago
|
||
(In reply to Emilio Cobos Álvarez (:emilio) from comment #13)
Yeah, it doesn't because the others don't use the text-editing code... Maybe I could make it more explicit and check for them anyway, or assert it's not called for those types...
This is not what I am seeing. For instance, I can reproduce the bug with <input type='month' maxlength='2'/>
.
Assignee | ||
Comment 15•5 years ago
|
||
Well that's a good catch. That's because we don't implement an special layout box for <input type=month>
... hmmp...
Reporter | ||
Comment 16•5 years ago
|
||
Yes, that's the point: maxlength
shouldn't apply by default everywhere the default text input UI is used, but only when the specification says so.
Assignee | ||
Comment 17•5 years ago
|
||
I revised the patch to be closer to the spec, but we should probably just check for <input type=number>
for the beta patch.
Updated•5 years ago
|
Assignee | ||
Comment 18•5 years ago
|
||
This checks only for number rather than InputType::MinAndMaxLengthApply
, which
is probably safer to uplift to beta.
Updated•5 years ago
|
Comment 19•5 years ago
|
||
Assignee | ||
Comment 21•5 years ago
|
||
Comment on attachment 9127842 [details]
Bug 1616620 - maxlength shouldn't apply to <input type=number> - beta version. r=smaug!
Beta/Release Uplift Approval Request
- User impact if declined: comment 0
- Is this code covered by automated tests?: Yes
- Has the fix been verified in Nightly?: No
- Needs manual test from QE?: Yes
- If yes, steps to reproduce: comment 0, or
<input type="number" maxlength="1">
and typing - List of other uplifts needed: None
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky): Relatively self-contained patch. Intentionally only checking for number to restore previous behavior, instead of the central patch which is slightly different to be closer to the HTML spec.
- String changes made/needed: none
Assignee | ||
Updated•5 years ago
|
Updated•5 years ago
|
Comment 23•5 years ago
|
||
Comment on attachment 9127842 [details]
Bug 1616620 - maxlength shouldn't apply to <input type=number> - beta version. r=smaug!
Low risk webcompat fix with tests, uplift approved for 74.0b6, thanks.
Updated•5 years ago
|
Comment 24•5 years ago
|
||
bugherder uplift |
Comment 25•5 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/00f7625a4423
https://hg.mozilla.org/mozilla-central/rev/7a4a562094c5
Updated•5 years ago
|
Comment 27•5 years ago
|
||
Reproduced the initial issue using an old Nightly build 75.0a1 (Build id: 20200213035745) using Windows 10.
Verified - Fixed in latest Nightly 75.0a1 (Build id: 20200220224950) and Beta 74.0b6 (Build id: 20200221001238) using Windows 10, Mac OS 10.14 and Ubuntu 18.04.
Description
•