WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Proposed patch (rev.3)
typemismatch-number-3.diff (text/plain), 9.20 KB, created by
Kent Tamura
on 2009-09-03 19:06:56 PDT
(
hide
)
Description:
Proposed patch (rev.3)
Filename:
MIME Type:
Creator:
Kent Tamura
Created:
2009-09-03 19:06:56 PDT
Size:
9.20 KB
patch
obsolete
>diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 34f273e..bce1bf4 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,14 @@ >+2009-09-03 Kent Tamura <tkent@chromium.org> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Tests for ValidityState::typeMismatch() for <input type=number>. >+ https://bugs.webkit.org/show_bug.cgi?id=28934 >+ >+ * fast/forms/ValidityState-typeMismatch-number-expected.txt: Added. >+ * fast/forms/ValidityState-typeMismatch-number.html: Added. >+ * fast/forms/resources/ValidityState-typeMismatch-number.js: Added. >+ > 2009-09-03 Alexey Proskuryakov <ap@apple.com> > > Reviewed by Darin Adler. >diff --git a/LayoutTests/fast/forms/ValidityState-typeMismatch-number-expected.txt b/LayoutTests/fast/forms/ValidityState-typeMismatch-number-expected.txt >new file mode 100644 >index 0000000..d6fac6f >--- /dev/null >+++ b/LayoutTests/fast/forms/ValidityState-typeMismatch-number-expected.txt >@@ -0,0 +1,37 @@ >+This test aims to check for typeMismatch flag with type=number input fields >+ >+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". >+ >+ >+PASS 0 is a correct valid number. >+PASS 10 is a correct valid number. >+PASS 01 is a correct valid number. >+PASS -0 is a correct valid number. >+PASS -1.2 is a correct valid number. >+PASS 1.2E10 is a correct valid number. >+PASS 1.2E-10 is a correct valid number. >+PASS 1.2E+10 is a correct valid number. >+PASS 12345678901234567890123456789012345678901234567890 is a correct valid number. >+PASS 0.12345678901234567890123456789012345678901234567890 is a correct valid number. >+PASS abc is a correct invalid number. >+PASS 0xff is a correct invalid number. >+PASS +1 is a correct invalid number. >+PASS 10 is a correct invalid number. >+PASS 10 is a correct invalid number. >+PASS 1,2 is a correct invalid number. >+PASS .2 is a correct invalid number. >+PASS 1E is a correct invalid number. >+PASS NaN is a correct invalid number. >+PASS nan is a correct invalid number. >+PASS Inf is a correct invalid number. >+PASS inf is a correct invalid number. >+PASS Infinity is a correct invalid number. >+PASS infinity is a correct invalid number. >+PASS is a correct valid number. >+PASS 1.2E65535 is a correct invalid number. >+PASS 1. is a correct valid number. >+PASS 1.2e10 is a correct valid number. >+PASS successfullyParsed is true >+ >+TEST COMPLETE >+ >diff --git a/LayoutTests/fast/forms/ValidityState-typeMismatch-number.html b/LayoutTests/fast/forms/ValidityState-typeMismatch-number.html >new file mode 100644 >index 0000000..29d1de8 >--- /dev/null >+++ b/LayoutTests/fast/forms/ValidityState-typeMismatch-number.html >@@ -0,0 +1,13 @@ >+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> >+<html> >+<head> >+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css"> >+<script src="../../fast/js/resources/js-test-pre.js"></script> >+</head> >+<body> >+<p id="description"></p> >+<div id="console"></div> >+<script src="resources/ValidityState-typeMismatch-number.js"></script> >+<script src="../../fast/js/resources/js-test-post.js"></script> >+</body> >+</html> >diff --git a/LayoutTests/fast/forms/resources/ValidityState-typeMismatch-number.js b/LayoutTests/fast/forms/resources/ValidityState-typeMismatch-number.js >new file mode 100644 >index 0000000..2e8a086 >--- /dev/null >+++ b/LayoutTests/fast/forms/resources/ValidityState-typeMismatch-number.js >@@ -0,0 +1,58 @@ >+description('This test aims to check for typeMismatch flag with type=number input fields'); >+ >+var i = document.createElement('input'); >+i.type = 'number'; >+ >+function check(value, mismatchExpected) >+{ >+ i.value = value; >+ var actual = i.validity.typeMismatch; >+ var didPass = actual == mismatchExpected; >+ var resultText = value + ' is ' + (didPass ? 'a correct ' : 'an incorrect ') + (actual ? 'invalid' : 'valid') + ' number.'; >+ if (didPass) >+ testPassed(resultText); >+ else >+ testFailed(resultText); >+} >+ >+// Valid values >+check('0', false); >+check('10', false); >+check('01', false); >+check('-0', false); >+check('-1.2', false); >+check('1.2E10', false); >+check('1.2E-10', false); >+check('1.2E+10', false); >+check('12345678901234567890123456789012345678901234567890', false); >+check('0.12345678901234567890123456789012345678901234567890', false); >+ >+// Invalid values >+check('abc', true); >+check('0xff', true); >+ >+check('+1', true); >+check(' 10', true); >+check('10 ', true); >+check('1,2', true); >+check('.2', true); >+check('1E', true); >+check('NaN', true); >+check('nan', true); >+check('Inf', true); >+check('inf', true); >+check('Infinity', true); >+check('infinity', true); >+ >+// Assume empty string as valid. >+check('', false); >+ >+// The spec allows, but our implementation doesn't >+// Huge exponent. >+check('1.2E65535', true); >+ >+// The spec doesn't allow, but our implementation does. >+check('1.', false); >+check('1.2e10', false); >+ >+var successfullyParsed = true; >diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog >index 8e7e9e9..352935a 100644 >--- a/WebCore/ChangeLog >+++ b/WebCore/ChangeLog >@@ -1,3 +1,19 @@ >+2009-09-03 Kent Tamura <tkent@chromium.org> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Implement ValidityState::typeMismatch() for <input type=number>. >+ https://bugs.webkit.org/show_bug.cgi?id=28934 >+ >+ Test: fast/forms/ValidityState-typeMismatch-number.html >+ >+ * html/HTMLInputElement.cpp: >+ (WebCore::HTMLInputElement::formStringToDouble): >+ * html/HTMLInputElement.h: >+ * html/ValidityState.cpp: >+ (WebCore::ValidityState::typeMismatch): >+ * html/ValidityState.h: >+ > 2009-09-03 Alexey Proskuryakov <ap@apple.com> > > Reviewed by Darin Adler. >diff --git a/WebCore/html/HTMLInputElement.cpp b/WebCore/html/HTMLInputElement.cpp >index f74f787..e85977f 100644 >--- a/WebCore/html/HTMLInputElement.cpp >+++ b/WebCore/html/HTMLInputElement.cpp >@@ -59,6 +59,7 @@ > #include "RenderTextControlSingleLine.h" > #include "RenderTheme.h" > #include "TextEvent.h" >+#include <wtf/MathExtras.h> > #include <wtf/StdLibExtras.h> > > using namespace std; >@@ -1772,6 +1773,29 @@ bool HTMLInputElement::placeholderShouldBeVisible() const > return InputElement::placeholderShouldBeVisible(this, this); > } > >+bool HTMLInputElement::formStringToDouble(const String& src, double* out) >+{ >+ // See HTML5 2.4.4.3 `Real numbers.' >+ >+ if (src.isEmpty()) >+ return false; >+ // String::toDouble() accepts leading + \t \n \v \f \r and SPACE, which are invalid in HTML5. >+ // So, check the first character. >+ if (src[0] != '-' && (src[0] < '0' || src[0] > '9')) >+ return false; >+ >+ bool valid = false; >+ double value = src.toDouble(&valid); >+ if (!valid) >+ return false; >+ // NaN and Infinity are not valid numbers according to the standard. >+ if (isnan(value) || isinf(value)) >+ return false; >+ if (out) >+ *out = value; >+ return true; >+} >+ > #if ENABLE(DATALIST) > HTMLElement* HTMLInputElement::list() const > { >diff --git a/WebCore/html/HTMLInputElement.h b/WebCore/html/HTMLInputElement.h >index 5054c7f..d951f40 100644 >--- a/WebCore/html/HTMLInputElement.h >+++ b/WebCore/html/HTMLInputElement.h >@@ -230,6 +230,11 @@ public: > virtual bool willValidate() const; > > virtual bool placeholderShouldBeVisible() const; >+ >+ // Converts the specified string to a floating number. >+ // If the conversion fails, the return value is false. Take care that leading or trailing unnecessary characters make failures. This returns false for an empty string input. >+ // The double* parameter may be 0. >+ static bool formStringToDouble(const String&, double*); > > protected: > virtual void willMoveToNewOwnerDocument(); >diff --git a/WebCore/html/ValidityState.cpp b/WebCore/html/ValidityState.cpp >index 86227d4..4c9c0b0 100644 >--- a/WebCore/html/ValidityState.cpp >+++ b/WebCore/html/ValidityState.cpp >@@ -23,14 +23,36 @@ > #include "config.h" > #include "ValidityState.h" > >+#include "HTMLInputElement.h" >+#include "HTMLNames.h" >+ > namespace WebCore { > >+using namespace HTMLNames; >+ > ValidityState::ValidityState(HTMLFormControlElement* parent) > : m_control(parent) > { > ASSERT(parent); > } > >+bool ValidityState::typeMismatch() >+{ >+ if (!control()->hasTagName(inputTag)) >+ return false; >+ >+ HTMLInputElement* input = static_cast<HTMLInputElement*>(control()); >+ String value = input->value(); >+ >+ if (value.isEmpty()) >+ return false; >+ >+ if (input->inputType() != HTMLInputElement::NUMBER) >+ return false; >+ // Check to make sure the number is valid, ignore the parsed number. >+ return !HTMLInputElement::formStringToDouble(value, 0); >+} >+ > bool ValidityState::valid() > { > bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow() || >diff --git a/WebCore/html/ValidityState.h b/WebCore/html/ValidityState.h >index 794822a..19bef41 100644 >--- a/WebCore/html/ValidityState.h >+++ b/WebCore/html/ValidityState.h >@@ -41,7 +41,7 @@ namespace WebCore { > void setCustomErrorMessage(const String& message) { m_customErrorMessage = message; } > > bool valueMissing() { return control()->valueMissing(); } >- bool typeMismatch() { return false; } >+ bool typeMismatch(); > bool patternMismatch() { return control()->patternMismatch(); } > bool tooLong() { return false; } > bool rangeUnderflow() { return false; }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 28934
:
38969
|
38976
|
39031
|
39046