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

https://bugs.webkit.org/show_bug.cgi?id=240761
rdar://91882650

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 2.5.4.3 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:
(WebCore::parseToDoubleForNumberType):

Canonical link: https://commits.webkit.org/250843@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294617 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 {
DefaultsToPassiveWheelListenersOnDocument,
DisallowsSettingAnyXHRHeaderFromFileURLs,
DoesNotDrainTheMicrotaskQueueWhenCallingObjC,
DoesNotParseStringEndingWithFullStopAsFloatingPointNumber,
DOMWindowReuseRestriction,
DownloadDelegatesCalledOnTheMainThread,
DropToNavigateDisallowedByDefault,
@@ -34,6 +34,10 @@
#include <wtf/Vector.h>
#include <wtf/dtoa.h>

#if PLATFORM(COCOA)
#include <wtf/cocoa/RuntimeApplicationChecksCocoa.h>
#endif

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 PLATFORM(COCOA)
if (!linkedOnOrAfterSDKWithBehavior(SDKAlignedBehavior::DoesNotParseStringEndingWithFullStopAsFloatingPointNumber))
allowStringsThatEndWithFullStop = true;
#endif

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

bool valid = false;

0 comments on commit 46e09eb

Please sign in to comment.