Title: [130835] trunk
Revision
130835
Author
tk...@chromium.org
Date
2012-10-09 18:40:11 -0700 (Tue, 09 Oct 2012)

Log Message

Should reject invalid dates constructed with multiple fields UI
https://bugs.webkit.org/show_bug.cgi?id=98727

Reviewed by Hajime Morita.

Source/WebCore:

In input[type=date] with multiple fields UI, we allow users to set
day-of-month value to 1-31 regardless of the month value. So users can
construct an invalid date such as "2012-02-31". We should sanitize such
values.

This change affects platforms with ENABLE_INPUT_TYPE_DATE &&
ENABLE_INPUT_MULTIPLE_FIELDS_UI.

Test: fast/forms/date-multiple-fields/date-multiple-fields-keyboard-events.html

* html/BaseDateAndTimeInputType.h:
(BaseDateAndTimeInputType): Make sanitizeValue protected to be called from
BaseMultipleFieldsDateAndTimeInputType.
* html/BaseMultipleFieldsDateAndTimeInputType.cpp:
(WebCore::BaseMultipleFieldsDateAndTimeInputType::editControlValueChanged):
Apply sanitizeValue to a value constructed in UI.
(WebCore::BaseMultipleFieldsDateAndTimeInputType::restoreFormControlState):
Ditto.

LayoutTests:

* fast/forms/date-multiple-fields/date-multiple-fields-keyboard-events-expected.txt: Added.
* fast/forms/date-multiple-fields/date-multiple-fields-keyboard-events.html: Added.
* fast/forms/month-multiple-fields/month-multiple-fields-keyboard-events-expected.txt:
* fast/forms/month-multiple-fields/month-multiple-fields-keyboard-events.html:
  Updated the test. 275760-12 is not a valid month value.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (130834 => 130835)


--- trunk/LayoutTests/ChangeLog	2012-10-10 01:23:11 UTC (rev 130834)
+++ trunk/LayoutTests/ChangeLog	2012-10-10 01:40:11 UTC (rev 130835)
@@ -1,3 +1,27 @@
+2012-10-09  Kent Tamura  <tk...@chromium.org>
+
+        Should reject invalid dates constructed with multiple fields UI
+        https://bugs.webkit.org/show_bug.cgi?id=98727
+
+        Reviewed by Hajime Morita.
+
+        * fast/forms/date-multiple-fields/date-multiple-fields-keyboard-events-expected.txt: Added.
+        * fast/forms/date-multiple-fields/date-multiple-fields-keyboard-events.html: Added.
+        * fast/forms/month-multiple-fields/month-multiple-fields-keyboard-events-expected.txt:
+        * fast/forms/month-multiple-fields/month-multiple-fields-keyboard-events.html:
+          Updated the test. 275760-12 is not a valid month value.
+
+2012-10-08  Tullio Lucena  <tullio.luc...@openbossa.org>
+
+        [Qt]REGRESSION(r128699): It made 2 fast/js/dfg tests assert
+        https://bugs.webkit.org/show_bug.cgi?id=96907
+
+        Reviewed by Csaba Osztrogonác.
+
+        Unskipping tests.
+
+        * platform/qt/TestExpectations:
+
 2012-10-09  Jeffrey Pfau  <jp...@apple.com>
 
         [Mac] Unreviewed, skipping http/tests/security/svg-image-leak.html

Copied: trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-keyboard-events-expected.txt (from rev 130834, trunk/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-keyboard-events-expected.txt) (0 => 130835)


--- trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-keyboard-events-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-keyboard-events-expected.txt	2012-10-10 01:40:11 UTC (rev 130835)
@@ -0,0 +1,61 @@
+Multiple fields UI of month input type with keyboard events
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Please run this with DumpRenderTree.
+
+Test following keys:
+Digits
+Left/Right - Move focus field inside element
+Up/Down - Increment/decrement value of focus field
+Tab - Move focus field
+Backspace - Make value empty
+  
+== Digit keys ==
+PASS input.value is "0012-09-20"
+== Left/Right keys ==
+PASS input.value is "2012-09-06"
+PASS document.activeElement.id is "input"
+== Up/Down keys ==
+PASS input.value is "2012-10-29"
+PASS input.value is "2012-08-29"
+== Up/Down keys on empty value ==
+PASS input.value is "2012-11-01"
+== Up/Down keys on empty value 2 ==
+PASS input.value is "2012-02-28"
+== Tab key ==
+PASS input.value is "2012-09-05"
+PASS input.value is "2012-09-07"
+PASS document.activeElement.id is "after"
+== Shfit+Tab key ==
+PASS input.value is "0003-09-30"
+PASS document.activeElement.id is "before"
+== Up key on maximum value ==
+PASS input.value is "0001-10-14"
+== Up key with a maximum attribute ==
+PASS input.value is "1000-01-01"
+== Down key on minimum value ==
+PASS input.value is ""
+== Down key with a minimum attribute ==
+PASS input.value is ""
+== Inconsistent min-max attributes ==
+PASS input.value is "1000-12-31"
+PASS input.value is "1999-12-31"
+== Make an invalid date ==
+PASS input.value is ""
+== Backspace key ==
+PASS input.value is ""
+== Delete key ==
+PASS input.value is ""
+== Typeahead ==
+PASS input.value is "2012-12-01"
+PASS input.value is "2012-12-02"
+== RTL Left/Right keys ==
+PASS input.value is "2012-01-28"
+PASS input.value is "2012-01-02"
+PASS input.value is "2012-03-02"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-keyboard-events.html (0 => 130835)


--- trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-keyboard-events.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-keyboard-events.html	2012-10-10 01:40:11 UTC (rev 130835)
@@ -0,0 +1,203 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<p>
+Please run this with DumpRenderTree.
+</p>
+Test following keys:
+<ul>
+    <li>Digits</li>
+    <li>Left/Right - Move focus field inside element</li>
+    <li>Up/Down - Increment/decrement value of focus field</li>
+    <li>Tab - Move focus field</li>
+    <li>Backspace - Make value empty</li>
+</ul>
+<input id="before">
+<input id="input" type="date">
+<input id="after">
+<div id="console"></div>
+<script>
+description('Multiple fields UI of month input type with keyboard events');
+var input = document.getElementById('input');
+
+function keyDown(key, modifiers)
+{
+    if (!window.eventSender)
+        return;
+    eventSender.keyDown(key, modifiers);
+}
+
+function beginTest(title, opt_value, opt_min, opt_max)
+{
+    debug('== ' + title + ' ==');
+    input.value = opt_value || '';
+    input.min = opt_min ? opt_min : '';
+    input.max = opt_max ? opt_max : '';
+    input.blur();
+    input.focus();
+}
+
+// We assume the date format is MM/dd/yyyy.
+
+beginTest('Digit keys');
+keyDown('9'); // -> 09/[dd]/yyyy
+keyDown('2'); // -> 09/[02]/yyyy
+keyDown('0'); // -> 09/20/[yyyy]
+keyDown('1'); // -> 09/20/[0001]
+keyDown('2'); // -> 09/20/[0012]
+keyDown('A'); // Ignored.
+shouldBeEqualToString('input.value', '0012-09-20');
+
+// FIXME: We should test type ahead time out. When event.leapForward() affects
+// keyboard event time stamp, we can uncomment this fragment.
+/*
+beginTest('Digit keys with type ahead timeout');
+keyDown('1'); // -> [01]/dd/yyyy
+leapForward(1100); // -> 01/[dd]/yyyy
+keyDown('1'); // -> 01/[01]/yyyy
+keyDown('5'); // -> 01/15/[yyyy]
+keyDown('6'); // -> 01/15/[0006]
+shouldBeEqualToString('input.value', '0006-01-15');
+*/
+
+beginTest('Left/Right keys', '2012-09-29');
+keyDown('rightArrow'); // -> 09/[29]/2012
+keyDown('5'); // -> 09/05/[2012]
+keyDown('leftArrow'); // -> 09/[05]/2012
+keyDown('6'); // -> 09/06/[2012]
+shouldBeEqualToString('input.value', '2012-09-06');
+keyDown('leftArrow'); // -> 09/[06]/2012
+keyDown('leftArrow'); // -> [09]/06/2012
+keyDown('leftArrow'); // -> [09]/06/2012
+shouldBeEqualToString('document.activeElement.id', 'input');
+
+beginTest('Up/Down keys', '2012-09-29');
+keyDown('upArrow'); // -> [10]/29/2012
+shouldBeEqualToString('input.value', '2012-10-29');
+keyDown('downArrow'); // -> [09]/29/2012
+keyDown('downArrow'); // -> [08]/29/2012
+shouldBeEqualToString('input.value', '2012-08-29');
+
+beginTest('Up/Down keys on empty value');
+keyDown('downArrow'); //  -> [12]/dd/yyyy
+keyDown('downArrow'); //  -> [11]/dd/yyyy
+keyDown('rightArrow'); // -> 11/[dd]/yyyy
+keyDown('upArrow'); //    -> 11/[01]/yyyy
+keyDown('upArrow'); //    -> 11/[02]/yyyy
+keyDown('downArrow'); //  -> 11/[01]/yyyy
+keyDown('rightArrow'); // -> 11/01/[yyyy]
+var currentYear = new Date().getFullYear();
+keyDown('upArrow'); // -> 11/01/[current year]
+shouldBeEqualToString('input.value', currentYear + '-11-01');
+
+beginTest('Up/Down keys on empty value 2');
+keyDown('upArrow'); //    -> [01]/dd/yyyy
+keyDown('upArrow'); //    -> [02]/dd/yyyy
+keyDown('rightArrow'); // -> 02/[dd]/yyyy
+keyDown('downArrow'); //  -> 02/[31]/yyyy
+keyDown('downArrow'); //  -> 02/[30]/yyyy
+keyDown('downArrow'); //  -> 02/[29]/yyyy
+keyDown('downArrow'); //  -> 02/[28]/yyyy
+keyDown('rightArrow'); // -> 02/28/[yyyy]
+currentYear = new Date().getFullYear();
+keyDown('downArrow'); // -> 02/28/[current year]
+shouldBeEqualToString('input.value', currentYear + '-02-28');
+
+beginTest('Tab key', '2012-09-30');
+keyDown('\t'); // -> 09/[30]/2012
+keyDown('5'); // -> 09/05/[2012]
+shouldBeEqualToString('input.value', '2012-09-05');
+keyDown('\t', ['shiftKey']); // -> 09/[05]/2012
+keyDown('7'); // -> 09/07/[2012]
+shouldBeEqualToString('input.value', '2012-09-07');
+keyDown('\t'); // -> Focus out.
+shouldBeEqualToString('document.activeElement.id', 'after');
+
+beginTest('Shfit+Tab key', '2012-09-30');
+after.focus();
+keyDown('\t', ['shiftKey']); // -> 09/30/[yyyy]
+keyDown('3'); // -> 09/30/[0003]
+shouldBeEqualToString('input.value', '0003-09-30');
+keyDown('\t', ['shiftKey']); // -> 09/[30]/0003
+keyDown('\t', ['shiftKey']); // -> [09]/30/0003
+keyDown('\t', ['shiftKey']); // -> Focus out.
+shouldBeEqualToString('document.activeElement.id', 'before');
+
+beginTest('Up key on maximum value', '275760-09-13');
+keyDown('upArrow'); // -> [10]/13/275760
+keyDown('\t'); //      -> 10/[13]/275760
+keyDown('upArrow'); // -> 10/[14]/275760
+keyDown('\t'); //      -> 10/14/[275760]
+keyDown('upArrow'); // -> 10/14/[0001]
+shouldBeEqualToString('input.value', '0001-10-14');
+beginTest('Up key with a maximum attribute', '1999-12-31', '1000-01-01', '1999-12-31');
+keyDown('upArrow'); // -> [01]/31/1999
+keyDown('\t'); //      -> 01/[31]/1999
+keyDown('upArrow'); // -> 01/[01]/1999
+keyDown('\t'); //      -> 01/01/[1999]
+keyDown('upArrow'); // -> 01/01/[1000]
+shouldBeEqualToString('input.value', '1000-01-01');
+
+beginTest('Down key on minimum value', '0001-01-01', 'bad min', 'wrong max');
+keyDown('downArrow'); // -> [12]/01/0001
+keyDown('\t'); //        -> 12/[01]/0001
+keyDown('downArrow'); // -> 12/[31]/0001
+keyDown('\t'); //        -> 12/31/[0001]
+keyDown('downArrow'); // -> 12/31/[275760], which is greater than the hard limit.
+shouldBeEqualToString('input.value', '');
+beginTest('Down key with a minimum attribute', '1000-01-01', '1000-01-01');
+keyDown('downArrow'); // -> [12]/01/1000
+keyDown('\t'); //        -> 12/[01]/1000
+keyDown('downArrow'); // -> 12/[31]/1000
+keyDown('\t'); //        -> 12/31/[1000]
+keyDown('downArrow'); // -> 12/31/275760, which is greater than the hard limit.
+shouldBeEqualToString('input.value', '');
+
+beginTest('Inconsistent min-max attributes', '1999-12-31', '1999-12-31', '1000-01-01');
+keyDown('\t'); // -> 12/[31]/1999
+keyDown('\t'); // -> 12/31/[1999]
+keyDown('upArrow'); // -> 12/31/[1000].  1000 is the swapped minimum year.
+shouldBeEqualToString('input.value', '1000-12-31');
+keyDown('downArrow'); // -> 12/31/[1999]
+shouldBeEqualToString('input.value', '1999-12-31');
+
+beginTest('Make an invalid date', '2012-02-01');
+keyDown('\t'); //        -> 02/[01]/2012
+keyDown('downArrow'); // -> 02/[31]/2012
+shouldBeEqualToString('input.value', ''); // 2012-02-31 is not a valid date.
+
+beginTest('Backspace key', '2012-09-20');
+keyDown("\b"); // -> [mm]/20/2012
+shouldBeEqualToString('input.value', '');
+
+beginTest('Delete key', '2012-09-30');
+keyDown("delete"); // -> [mm]/30/2012
+shouldBeEqualToString('input.value', '');
+
+beginTest('Typeahead', '2012-12-31');
+keyDown('rightArrow'); // -> 12/[31]/2012
+keyDown('1'); //          -> 12/[01]/2012
+shouldBeEqualToString('input.value', '2012-12-01');
+keyDown('leftArrow'); //  -> [12]/01/2012
+keyDown('rightArrow'); // -> 12/[01]/2012
+keyDown('2'); //          -> 12/[02]/2012
+shouldBeEqualToString('input.value', '2012-12-02');
+
+beginTest('RTL Left/Right keys', '2012-09-28');
+input.setAttribute("dir", "rtl"); // -> 2012/28/[09]
+keyDown('1'); //          -> 2012/28/[01]
+shouldBeEqualToString('input.value', '2012-01-28');
+keyDown('leftArrow'); //  -> 2012/[28]/01
+keyDown('2'); //          -> 2012/[02]/01
+shouldBeEqualToString('input.value', '2012-01-02');
+keyDown('rightArrow'); // -> 2012/02/[01]
+keyDown('3'); //          -> 2012/02/[03]
+shouldBeEqualToString('input.value', '2012-03-02');
+</script>
+<script src=""
+</body>
+</html>
Property changes on: trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-keyboard-events.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-keyboard-events-expected.txt (130834 => 130835)


--- trunk/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-keyboard-events-expected.txt	2012-10-10 01:23:11 UTC (rev 130834)
+++ trunk/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-keyboard-events-expected.txt	2012-10-10 01:40:11 UTC (rev 130835)
@@ -36,9 +36,9 @@
 == Up key with a maximum attribute ==
 PASS input.value is "0001-01"
 == Down key on minimum value ==
-PASS input.value is "275760-12"
+PASS input.value is ""
 == Down key with a minimum attribute ==
-PASS input.value is "275760-12"
+PASS input.value is ""
 == Inconsistent min-max attributes ==
 PASS input.value is "1000-12"
 PASS input.value is "1999-12"

Modified: trunk/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-keyboard-events.html (130834 => 130835)


--- trunk/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-keyboard-events.html	2012-10-10 01:23:11 UTC (rev 130834)
+++ trunk/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-keyboard-events.html	2012-10-10 01:40:11 UTC (rev 130835)
@@ -134,15 +134,15 @@
 shouldBeEqualToString('input.value', '0001-01');
 
 beginTest('Down key on minimum value', '0001-01', 'bad min', 'wrong max');
-keyDown('downArrow');
+keyDown('downArrow'); // -> 0001-12
 keyDown('\t');
-keyDown('downArrow');
-shouldBeEqualToString('input.value', '275760-12');
+keyDown('downArrow'); // -> 275760-12, which is greater than the hard limit.
+shouldBeEqualToString('input.value', '');
 beginTest('Down key with a minimum attribute', '0001-01', '0001-01');
-keyDown('downArrow');
+keyDown('downArrow'); // -> 0001-12
 keyDown('\t');
-keyDown('downArrow');
-shouldBeEqualToString('input.value', '275760-12');
+keyDown('downArrow'); // -> 275760-12, which is greater than the hard limit.
+shouldBeEqualToString('input.value', '');
 
 beginTest('Inconsistent min-max attributes', '1999-12', '1999-12', '1000-01');
 keyDown('\t');

Modified: trunk/Source/WebCore/ChangeLog (130834 => 130835)


--- trunk/Source/WebCore/ChangeLog	2012-10-10 01:23:11 UTC (rev 130834)
+++ trunk/Source/WebCore/ChangeLog	2012-10-10 01:40:11 UTC (rev 130835)
@@ -1,3 +1,29 @@
+2012-10-09  Kent Tamura  <tk...@chromium.org>
+
+        Should reject invalid dates constructed with multiple fields UI
+        https://bugs.webkit.org/show_bug.cgi?id=98727
+
+        Reviewed by Hajime Morita.
+
+        In input[type=date] with multiple fields UI, we allow users to set
+        day-of-month value to 1-31 regardless of the month value. So users can
+        construct an invalid date such as "2012-02-31". We should sanitize such
+        values.
+
+        This change affects platforms with ENABLE_INPUT_TYPE_DATE &&
+        ENABLE_INPUT_MULTIPLE_FIELDS_UI.
+
+        Test: fast/forms/date-multiple-fields/date-multiple-fields-keyboard-events.html
+
+        * html/BaseDateAndTimeInputType.h:
+        (BaseDateAndTimeInputType): Make sanitizeValue protected to be called from
+        BaseMultipleFieldsDateAndTimeInputType.
+        * html/BaseMultipleFieldsDateAndTimeInputType.cpp:
+        (WebCore::BaseMultipleFieldsDateAndTimeInputType::editControlValueChanged):
+        Apply sanitizeValue to a value constructed in UI.
+        (WebCore::BaseMultipleFieldsDateAndTimeInputType::restoreFormControlState):
+        Ditto.
+
 2012-10-09  Joe Mason  <jma...@rim.com>
 
         Check for null m_frame in NetworkJob

Modified: trunk/Source/WebCore/html/BaseDateAndTimeInputType.h (130834 => 130835)


--- trunk/Source/WebCore/html/BaseDateAndTimeInputType.h	2012-10-10 01:23:11 UTC (rev 130834)
+++ trunk/Source/WebCore/html/BaseDateAndTimeInputType.h	2012-10-10 01:40:11 UTC (rev 130835)
@@ -44,6 +44,7 @@
     virtual void handleKeydownEvent(KeyboardEvent*) OVERRIDE;
     virtual Decimal parseToNumber(const String&, const Decimal&) const OVERRIDE;
     virtual bool parseToDateComponents(const String&, DateComponents*) const OVERRIDE;
+    virtual String sanitizeValue(const String&) const OVERRIDE;
     virtual String serialize(const Decimal&) const OVERRIDE;
     String serializeWithComponents(const DateComponents&) const;
     virtual bool setMillisecondToDateComponents(double, DateComponents*) const = 0;
@@ -63,7 +64,6 @@
     virtual String localizeValue(const String&) const OVERRIDE;
     virtual String visibleValue() const OVERRIDE;
     virtual String convertFromVisibleValue(const String&) const OVERRIDE;
-    virtual String sanitizeValue(const String&) const OVERRIDE;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp (130834 => 130835)


--- trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp	2012-10-10 01:23:11 UTC (rev 130834)
+++ trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp	2012-10-10 01:40:11 UTC (rev 130835)
@@ -71,7 +71,7 @@
 void BaseMultipleFieldsDateAndTimeInputType::editControlValueChanged()
 {
     RefPtr<HTMLInputElement> input(element());
-    input->setValueInternal(m_dateTimeEditElement->value(), DispatchNoEvent);
+    input->setValueInternal(sanitizeValue(m_dateTimeEditElement->value()), DispatchNoEvent);
     input->setNeedsStyleRecalc();
     input->dispatchFormControlInputEvent();
     input->dispatchFormControlChangeEvent();
@@ -233,7 +233,7 @@
     setMillisecondToDateComponents(createStepRange(AnyIsDefaultStep).minimum().toDouble(), &date);
     DateTimeFieldsState dateTimeFieldsState = DateTimeFieldsState::restoreFormControlState(state);
     m_dateTimeEditElement->setValueAsDateTimeFieldsState(dateTimeFieldsState, date);
-    element()->setValueInternal(m_dateTimeEditElement->value(), DispatchNoEvent);
+    element()->setValueInternal(sanitizeValue(m_dateTimeEditElement->value()), DispatchNoEvent);
 }
 
 FormControlState BaseMultipleFieldsDateAndTimeInputType::saveFormControlState() const
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to