From f5d631aae9ca0b47b6b247fc2dd7932d6aa57a42 Mon Sep 17 00:00:00 2001 From: Dianna Smith Date: Thu, 20 Jul 2023 15:59:12 -0400 Subject: [PATCH] Backed out changeset 4b2b24f16463 (bug 1839572) for causing failures in HTMLInputElement.cpp a=backout --- dom/html/HTMLInputElement.cpp | 21 ++++------ .../number-constraint-validation.html | 42 ------------------- 2 files changed, 9 insertions(+), 54 deletions(-) delete mode 100644 testing/web-platform/tests/html/semantics/forms/the-input-element/number-constraint-validation.html diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 184d529ad6f37..4a3e5b2c935ad 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -19,7 +19,6 @@ #include "mozilla/dom/FileSystemUtils.h" #include "mozilla/dom/FormData.h" #include "mozilla/dom/GetFilesHelper.h" -#include "mozilla/dom/NumericInputTypes.h" #include "mozilla/dom/WindowContext.h" #include "mozilla/dom/InputType.h" #include "mozilla/dom/UserActivation.h" @@ -1633,10 +1632,15 @@ void HTMLInputElement::SetValue(const nsAString& aValue, CallerType aCallerType, // NOTE: this is currently quite expensive work (too much string // manipulation). We should probably optimize that. nsAutoString currentValue; - GetNonFileValueInternal(currentValue); + GetValue(currentValue, aCallerType); + // Some types sanitize value, so GetValue doesn't return pure + // previous value correctly. + // + // FIXME(emilio): Shouldn't above just use GetNonFileValueInternal() to + // get the unsanitized value? nsresult rv = SetValueInternal( - aValue, ¤tValue, + aValue, SanitizesOnValueGetter() ? nullptr : ¤tValue, {ValueSetterOption::ByContentAPI, ValueSetterOption::SetValueChanged, ValueSetterOption::MoveCursorToEndIfValueChanged}); if (NS_FAILED(rv)) { @@ -2641,14 +2645,7 @@ nsresult HTMLInputElement::SetValueInternal( // prevent doing it if it's useless. nsAutoString value(aValue); - if (mDoneCreating && - !(mType == FormControlType::InputNumber && - aOptions.contains(ValueSetterOption::BySetUserInputAPI))) { - // When the value of a number input is set by a script, we need to make - // sure the value is a valid floating-point number. - // https://html.spec.whatwg.org/#valid-floating-point-number - // When it's set by a user, however, we need to be more permissive, so - // we don't sanitize its value here. See bug 1839572. + if (mDoneCreating) { SanitizeValue(value); } // else DoneCreatingElement calls us again once mDoneCreating is true @@ -4589,7 +4586,7 @@ void HTMLInputElement::SanitizeValue(nsAString& aValue, aValue); } break; case FormControlType::InputNumber: { - if (aKind == SanitizationKind::Other && !aValue.IsEmpty() && + if (!aValue.IsEmpty() && (aValue.First() == '+' || aValue.Last() == '.')) { // A value with a leading plus or trailing dot should fail to parse. // However, the localized parser accepts this, and when we convert it diff --git a/testing/web-platform/tests/html/semantics/forms/the-input-element/number-constraint-validation.html b/testing/web-platform/tests/html/semantics/forms/the-input-element/number-constraint-validation.html deleted file mode 100644 index 959726bb50d9d..0000000000000 --- a/testing/web-platform/tests/html/semantics/forms/the-input-element/number-constraint-validation.html +++ /dev/null @@ -1,42 +0,0 @@ - - -Form input type=number constraint validation - - - - - - -
- -