Closed Bug 1839572 Opened 2 years ago Closed 2 years ago

input[type=number] does not return expected value when there is a trailing decimal point [was: does not have the :invalid pseudo class for some invalid inputs]

Categories

(Core :: DOM: Forms, defect)

Firefox 116
defect

Tracking

()

RESOLVED FIXED
117 Branch
Tracking Status
firefox-esr102 --- unaffected
firefox-esr115 --- wontfix
firefox114 --- wontfix
firefox115 --- wontfix
firefox116 --- wontfix
firefox117 --- fixed

People

(Reporter: Kai.Ruhnau, Assigned: avandolder)

References

(Regression)

Details

(Keywords: regression)

Attachments

(1 file, 1 obsolete file)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.51

Steps to reproduce:

Go to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number and start using the input type=number in the "Try it" section.

The initial input state is .value='' and .matches(':invalid')=false.
For valid inputs like "20", the input state is .value='20' and .matches(':invalid')=false.
For invalid inputs like "a", the input state is .value='' and .matches(':invalid')=true.
That's all expected and good.

However, for an input of "20." (note the additional dot), the input is now in an inconsistent state.

Actual results:

The input state is .value='' and .matches(':invalid')=false, that is something was entered, it couldn't be interpreted, but is still considered valid.

Expected results:

I can think of two outcomes: Either "20." is invalid and this is reflected in the pseudo class, or (and this is the preferred behavior as it matches Chromium) "20." is valid and interpreted as ".value='20'"

Note that the spinners of the input consider "20." valid enough to increase to 21 or decrease to 19 while doing nothing for inputs like "a"

The Bugbug bot thinks this bug should belong to the 'Core::Layout: Form Controls' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Layout: Form Controls
Product: Firefox → Core

I believe "20." should be valid; the dot is a decimal point, and this is equivalent to "20.0" or just "20". So the bug here is that when the input has a trailing dot (and no following digit), it's returning an empty .value string.

Interestingly, .valueAsNumber returns the expected number.

Severity: -- → S3
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: input[type=number] does not have the :invalid pseudo class for some invalid inputs → input[type=number] does not return expected value when there is a trailing decimal point [was: does not have the :invalid pseudo class for some invalid inputs]
Component: Layout: Form Controls → DOM: Forms

Set release status flags based on info from the regressing bug 1821569

Hi all, according to this post v113 is affected too. Just as some posters say, our users cannot enter decimal numbers in Firefox as it gets cleared out. Copying a decimal value into the input field, however, does not clear it. When a trailing dot is entered OnInput event is fired with an empty string as a value

Jonathan, do you think this could have a serious webcompat impact? Thanks

Flags: needinfo?(jfkthame)

Set release status flags based on info from the regressing bug 1821569

According to the HTML spec, a number with a trailing decimal point is not considered valid, and should fail to parse. This is checked by the html/semantics/forms/the-input-element/number.html web platform test, which Firefox was failing before bug 1821569 was resolved. That patch did not include the constraint validation that should be setting the bad input flag, so that needs to be fixed at the very least.

Flags: needinfo?(avandolder)

(In reply to Adam Vandolder [:avandolder] from comment #8)

According to the HTML spec, a number with a trailing decimal point is not considered valid,

So it is....

and should fail to parse.

...but I'm not sure this follows. The parsing rules there, AFAICT, will successfully parse a number with a trailing decimal point: in particular, step 13.2 does not return an error, it simply jumps to the "conversion" stage.

This is checked by the html/semantics/forms/the-input-element/number.html web platform test, which Firefox was failing before bug 1821569 was resolved.

I'm finding it hard to follow all the twists and turns of the spec, but I think there may be two different scenarios to consider. When the value attribute is set, the spec tells us to run the value sanitization algorithm, which would replace a number-with-trailing-period with an empty string. That's what is tested by the above WPT test.

But when the user is changing the value, the spec seems to be telling us to "apply[ing] the rules for parsing floating-point number values to it", which would interpret "10." as the number 10.

It seems wrong/inconsistent that at present, when the user types "123." into the number field, we return an empty string for value, yet we return the number 123 for valueAsNumber. The spec for this tells us that

The valueAsNumber IDL attribute represents the value of the element, interpreted as a number.

but if the value has been set to an empty string (because "123." was not a valid floating-point number), how can we return 123 here?

Flags: needinfo?(jfkthame)

(In reply to Pascal Chevrel:pascalc from comment #6)

Jonathan, do you think this could have a serious webcompat impact? Thanks

Yes, it looks like it. As well as comment 5 here, we have regression reports like bug 1821569 and bug 1838254, which I think have been incorrectly closed as invalid. This seems to indicate people are encountering (and being surprised by) the behavior change.

(In reply to Jonathan Kew [:jfkthame] from comment #9)

I'm finding it hard to follow all the twists and turns of the spec, but I think there may be two different scenarios to consider. When the value attribute is set, the spec tells us to run the value sanitization algorithm, which would replace a number-with-trailing-period with an empty string. That's what is tested by the above WPT test.

But when the user is changing the value, the spec seems to be telling us to "apply[ing] the rules for parsing floating-point number values to it", which would interpret "10." as the number 10.

Ah, alright. That change was unintentional - the issue seems to be that we're sanitizing the input value in more cases than the spec says to, which was fine when the sanitizer was only running the parsing algorithm, and not checking the "valid floating-point number" part.

Ah, alright. That change was unintentional - the issue seems to be that we're sanitizing the input value in more cases than the spec says to, which was fine when the sanitizer was only running the parsing algorithm, and not checking the "valid floating-point number" part.

:avandolder do you have any rough idea when you plan on having a look at patching this?
Wondering if we will have something in time for Fx116 or potentially a FX115 dot release ride along

Flags: needinfo?(avandolder)
Assignee: nobody → avandolder
Status: NEW → ASSIGNED

(In reply to Donal Meehan [:dmeehan] from comment #12)

Ah, alright. That change was unintentional - the issue seems to be that we're sanitizing the input value in more cases than the spec says to, which was fine when the sanitizer was only running the parsing algorithm, and not checking the "valid floating-point number" part.

:avandolder do you have any rough idea when you plan on having a look at patching this?
Wondering if we will have something in time for Fx116 or potentially a FX115 dot release ride along

Hopefully will be able to land this patch before Fx116.

Flags: needinfo?(avandolder)
Pushed by avandolder@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/4b2b24f16463 Fix number input value sanitization. r=dom-core,edgar
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/41112 for changes under testing/web-platform/tests
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 117 Branch

Adam, do you want to request an uplift to our last 116 beta? Thanks

Flags: needinfo?(avandolder)

Sweet, thanks!

Upstream PR merged by moz-wptsync-bot

(In reply to Pascal Chevrel:pascalc from comment #18)

Adam, do you want to request an uplift to our last 116 beta? Thanks

Yes, if possible.

Flags: needinfo?(avandolder)

Approval Request Comment
[Feature/Bug causing the regression]: Interop-2022 web platform test fix from bug 1821569
[User impact if declined]: Number inputs will fail to accept user inputted values with leading '+' or '.', in particular breaking sites that check for input values upon each keystroke, which will fail as soon as a '.' is entered.
[Is this code covered by automated tests?]: Yes
[Has the fix been verified in Nightly?]: Yes
[Needs manual test from QE? If yes, steps to reproduce]: No
[List of other uplifts needed for the feature/fix]: n/a
[Is the change risky?]: No
[Why is the change risky/not risky?]: Fixes an unintended regression and aligns Firefox with the HTML specification. Regression has only existed for 4 months, so it is unlikely any sites are relying on it.
[String changes made/needed]: n/a

Attachment #9344917 - Flags: approval-mozilla-beta?
Comment on attachment 9344917 [details] Beta Uplift Approval Request Approval Request Comment [Feature/Bug causing the regression]: Interop-2022 web platform test fix from bug 1821569 [User impact if declined]: Number inputs will fail to accept user inputted values with leading '+' or '.', in particular breaking sites that check for input values upon each keystroke, which will fail as soon as a '.' is entered. [Is this code covered by automated tests?]: Yes [Has the fix been verified in Nightly?]: Yes [Needs manual test from QE? If yes, steps to reproduce]: No [List of other uplifts needed for the feature/fix]: n/a [Is the change risky?]: No [Why is the change risky/not risky?]: Fixes an unintended regression and aligns Firefox with the HTML specification. Regression has only existed for 4 months, so it is unlikely any sites are relying on it. [String changes made/needed]: n/a

Comment on attachment 9342840 [details]
Bug 1839572 - Fix number input value sanitization. r=#dom-core

Approved for 116.0b8

Attachment #9342840 - Flags: approval-mozilla-beta+

Comment on attachment 9344917 [details]
Beta Uplift Approval Request

clearing, since i added the approval in the phab patch

Attachment #9344917 - Flags: approval-mozilla-beta?

Backed out for causing build bustages in HTMLInputElement.cpp
Backout link
Push with failures
Failure log

most likely a dependency on bug 1842027, marking as wontfix for 116

I'm confused about the patch, why doing that only on SanitizationKind::Other? Feels pretty random, can we pass a more reasonable reason for the places we need this?

Flags: needinfo?(avandolder)
Attachment #9342840 - Attachment is obsolete: true

The patch for bug 1857506 seems to have addressed this.

Flags: needinfo?(avandolder)
See Also: → 1945333
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: