Skip to content
Browse files
REGRESSION (r290124): Unable to insert decimal point when typing in a…
… number text field in QQ app

Reviewed by Chris Dumez and Tim Horton.

After the changes in r290124, we no longer treat strings that end with a full stop (e.g. "1.") as valid floating point
numbers, per section of the HTML spec (Real numbers), which states that a decimal number that contains a full
stop character (".") must be succeeded by one or more digit characters. The HTML spec later references this when
describing how to sanitize the value of number inputs -- namely, we return the value of the input if it's a valid
floating point number, and otherwise return the empty string.

However, the QQ app still relies on the fact that strings of the form are "<n>." are valid floating point numbers; this
is because the app installs a `keyup` event handler that asks for the input's value, removes all non-digit and non-
full-stop characters, and then sets the text field's value to this new string. Because strings ending with a period are
no longer valid floating point numbers, it's now very difficult to type decimals of the form `"N.N"` into some text
fields in the QQ app, since the input is cleared out each time the user types "." at the end of the field.

This new behavior (more or less) matches Chrome and Firefox; to maintain consistent behavior with other browsers without
breaking binary compatibility, we guard this new behavior with a linked-on-or-after check.

* Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.h:
* Source/WebCore/html/parser/HTMLParserIdioms.cpp:

Canonical link:
git-svn-id: 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
whsieh committed May 21, 2022
1 parent 00360b3 commit 46e09eb6cded2055256ae332f4852cc6586e0d4e
Showing 2 changed files with 12 additions and 1 deletion.
@@ -44,6 +44,7 @@ enum class SDKAlignedBehavior {
@@ -34,6 +34,10 @@
#include <wtf/Vector.h>
#include <wtf/dtoa.h>

#include <wtf/cocoa/RuntimeApplicationChecksCocoa.h>

namespace WebCore {

template <typename CharType>
@@ -134,7 +138,13 @@ double parseToDoubleForNumberType(StringView string, double fallbackValue)
if (firstCharacter != '-' && firstCharacter != '.' && !isASCIIDigit(firstCharacter))
return fallbackValue;

if (string.endsWith('.'))
bool allowStringsThatEndWithFullStop = false;
if (!linkedOnOrAfterSDKWithBehavior(SDKAlignedBehavior::DoesNotParseStringEndingWithFullStopAsFloatingPointNumber))
allowStringsThatEndWithFullStop = true;

if (string.endsWith('.') && !allowStringsThatEndWithFullStop)
return fallbackValue;

bool valid = false;

0 comments on commit 46e09eb

Please sign in to comment.