Commit 0a776807 authored by joepeck@webkit.org's avatar joepeck@webkit.org

<http://webkit.org/b/59951> Implement Date and Time Input Value Sanitization

Source/WebCore:

Sanitize non-parsable incoming strings to the empty string.

Reviewed by Kent Tamura.

Covered by existing tests.

* html/BaseDateAndTimeInputType.h:
* html/BaseDateAndTimeInputType.cpp:
(WebCore::BaseDateAndTimeInputType::sanitizeValue): check if the
incoming string is valid. If not just return the empty string.

LayoutTests:

Update ValidityState typeMismatch tests for date types, since
setting an invalid value now sanitized to the empty string.
So, what used to be an invalid value with a typeMismatch is
now a valid empty string and there is never a typeMismatch.

  - for rangeOverflow / rangeUnderflow tests update the
    test to point out when a value was sanitized.
  - for typeMismatch tests, typeMismatch can no longer
    happen for sanitized values. Change the test to output
    if the value was sanitized or not and ensure that
    we are never in a typeMismatch state. Disabled inputs
    are also sanitized when their value changes.

Reviewed by Kent Tamura.

* fast/forms/date/ValidityState-rangeOverflow-date-expected.txt:
* fast/forms/date/ValidityState-rangeOverflow-date.html:
* fast/forms/date/ValidityState-rangeUnderflow-date-expected.txt:
* fast/forms/date/ValidityState-rangeUnderflow-date.html:
* fast/forms/date/ValidityState-typeMismatch-date-expected.txt:
* fast/forms/date/ValidityState-typeMismatch-date.html:
* fast/forms/datetime/ValidityState-rangeOverflow-datetime-expected.txt:
* fast/forms/datetime/ValidityState-rangeOverflow-datetime.html:
* fast/forms/datetime/ValidityState-rangeUnderflow-datetime-expected.txt:
* fast/forms/datetime/ValidityState-rangeUnderflow-datetime.html:
* fast/forms/datetime/ValidityState-typeMismatch-datetime-expected.txt:
* fast/forms/datetime/ValidityState-typeMismatch-datetime.html:
* fast/forms/datetimelocal/ValidityState-rangeOverflow-datetimelocal-expected.txt:
* fast/forms/datetimelocal/ValidityState-rangeOverflow-datetimelocal.html:
* fast/forms/datetimelocal/ValidityState-rangeUnderflow-datetimelocal-expected.txt:
* fast/forms/datetimelocal/ValidityState-rangeUnderflow-datetimelocal.html:
* fast/forms/datetimelocal/ValidityState-typeMismatch-datetimelocal-expected.txt:
* fast/forms/datetimelocal/ValidityState-typeMismatch-datetimelocal.html:
* fast/forms/month/ValidityState-rangeOverflow-month-expected.txt:
* fast/forms/month/ValidityState-rangeOverflow-month.html:
* fast/forms/month/ValidityState-rangeUnderflow-month-expected.txt:
* fast/forms/month/ValidityState-rangeUnderflow-month.html:
* fast/forms/month/ValidityState-typeMismatch-month-expected.txt:
* fast/forms/month/ValidityState-typeMismatch-month.html:
* fast/forms/time/ValidityState-rangeOverflow-time-expected.txt:
* fast/forms/time/ValidityState-rangeOverflow-time.html:
* fast/forms/time/ValidityState-rangeUnderflow-time-expected.txt:
* fast/forms/time/ValidityState-rangeUnderflow-time.html:
* fast/forms/time/ValidityState-typeMismatch-time-expected.txt:
* fast/forms/time/ValidityState-typeMismatch-time.html:
* fast/forms/week/ValidityState-rangeOverflow-week-expected.txt:
* fast/forms/week/ValidityState-rangeOverflow-week.html:
* fast/forms/week/ValidityState-rangeUnderflow-week-expected.txt:
* fast/forms/week/ValidityState-rangeUnderflow-week.html:
* fast/forms/week/ValidityState-typeMismatch-week-expected.txt:
* fast/forms/week/ValidityState-typeMismatch-week.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@103957 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 548c2605
2011-12-22 Joseph Pecoraro <pecoraro@apple.com>
Implement Date and Time Input Value Sanitization
https://bugs.webkit.org/show_bug.cgi?id=59951
Update ValidityState typeMismatch tests for date types, since
setting an invalid value now sanitized to the empty string.
So, what used to be an invalid value with a typeMismatch is
now a valid empty string and there is never a typeMismatch.
- for rangeOverflow / rangeUnderflow tests update the
test to point out when a value was sanitized.
- for typeMismatch tests, typeMismatch can no longer
happen for sanitized values. Change the test to output
if the value was sanitized or not and ensure that
we are never in a typeMismatch state. Disabled inputs
are also sanitized when their value changes.
Reviewed by Kent Tamura.
* fast/forms/date/ValidityState-rangeOverflow-date-expected.txt:
* fast/forms/date/ValidityState-rangeOverflow-date.html:
* fast/forms/date/ValidityState-rangeUnderflow-date-expected.txt:
* fast/forms/date/ValidityState-rangeUnderflow-date.html:
* fast/forms/date/ValidityState-typeMismatch-date-expected.txt:
* fast/forms/date/ValidityState-typeMismatch-date.html:
* fast/forms/datetime/ValidityState-rangeOverflow-datetime-expected.txt:
* fast/forms/datetime/ValidityState-rangeOverflow-datetime.html:
* fast/forms/datetime/ValidityState-rangeUnderflow-datetime-expected.txt:
* fast/forms/datetime/ValidityState-rangeUnderflow-datetime.html:
* fast/forms/datetime/ValidityState-typeMismatch-datetime-expected.txt:
* fast/forms/datetime/ValidityState-typeMismatch-datetime.html:
* fast/forms/datetimelocal/ValidityState-rangeOverflow-datetimelocal-expected.txt:
* fast/forms/datetimelocal/ValidityState-rangeOverflow-datetimelocal.html:
* fast/forms/datetimelocal/ValidityState-rangeUnderflow-datetimelocal-expected.txt:
* fast/forms/datetimelocal/ValidityState-rangeUnderflow-datetimelocal.html:
* fast/forms/datetimelocal/ValidityState-typeMismatch-datetimelocal-expected.txt:
* fast/forms/datetimelocal/ValidityState-typeMismatch-datetimelocal.html:
* fast/forms/month/ValidityState-rangeOverflow-month-expected.txt:
* fast/forms/month/ValidityState-rangeOverflow-month.html:
* fast/forms/month/ValidityState-rangeUnderflow-month-expected.txt:
* fast/forms/month/ValidityState-rangeUnderflow-month.html:
* fast/forms/month/ValidityState-typeMismatch-month-expected.txt:
* fast/forms/month/ValidityState-typeMismatch-month.html:
* fast/forms/time/ValidityState-rangeOverflow-time-expected.txt:
* fast/forms/time/ValidityState-rangeOverflow-time.html:
* fast/forms/time/ValidityState-rangeUnderflow-time-expected.txt:
* fast/forms/time/ValidityState-rangeUnderflow-time.html:
* fast/forms/time/ValidityState-typeMismatch-time-expected.txt:
* fast/forms/time/ValidityState-typeMismatch-time.html:
* fast/forms/week/ValidityState-rangeOverflow-week-expected.txt:
* fast/forms/week/ValidityState-rangeOverflow-week.html:
* fast/forms/week/ValidityState-rangeUnderflow-week-expected.txt:
* fast/forms/week/ValidityState-rangeUnderflow-week.html:
* fast/forms/week/ValidityState-typeMismatch-week-expected.txt:
* fast/forms/week/ValidityState-typeMismatch-week.html:
2012-01-03 Alexis Menard <alexis.menard@openbossa.org>
getComputedStyle should return shorthands properties with the minimum number of sides possible.
......@@ -9,7 +9,7 @@ PASS The value "2010-01-27" doesn't overflow the maximum value "foo".
PASS The value "2010-01-27" doesn't overflow the maximum value "2010-01-27".
PASS The value "2010-01-27" doesn't overflow the maximum value "2010-01-28".
PASS The value "2010-01-27" doesn't overflow the maximum value "2011-01-26".
PASS The value "foo" doesn't overflow the maximum value "2011-01-26".
PASS The value "" sanitized from "foo" doesn't overflow the maximum value "2011-01-26".
PASS The value "2010-01-27" doesn't overflow the maximum value "0000-01-01".
PASS The value "2010-01-27" overflows the maximum value "2010-01-26".
PASS The value "9999-01-01" overflows the maximum value "2010-12-31".
......
......@@ -26,13 +26,14 @@ function checkOverflow(value, max, disabled)
testFailed(resultText);
}
function checkNotOverflow(value, max, disabled)
function checkNotOverflow(value, max, disabled, sanitized)
{
input.value = value;
input.max = max;
input.disabled = !!disabled;
var overflow = input.validity.rangeOverflow;
var resultText = 'The value "' + input.value + '" ' +
(sanitized ? 'sanitized from "' + value + '" ' : '') +
(overflow ? 'overflows' : 'doesn\'t overflow') +
' the maximum value "' + input.max + '"' + (disabled ? ' when disabled.' : '.');
if (overflow)
......@@ -41,6 +42,12 @@ function checkNotOverflow(value, max, disabled)
testPassed(resultText);
}
function checkSanitizedValueNotOverflow(value, max, disabled)
{
// For date types, invalid values are sanitized to "".
checkNotOverflow(value, max, disabled, true);
}
input.type = 'date';
input.min = '';
// No overflow cases
......@@ -50,7 +57,7 @@ checkNotOverflow('2010-01-27', 'foo');
checkNotOverflow('2010-01-27', '2010-01-27');
checkNotOverflow('2010-01-27', '2010-01-28');
checkNotOverflow('2010-01-27', '2011-01-26');
checkNotOverflow('foo', '2011-01-26');
checkSanitizedValueNotOverflow('foo', '2011-01-26');
checkNotOverflow('2010-01-27', '0000-01-01'); // Too small max value.
// Overflow cases
......
......@@ -10,7 +10,7 @@ PASS The value "1000-01-01" doesn't underflow the minimum value "".
PASS The value "1582-10-15" doesn't underflow the minimum value "".
PASS The value "2010-01-27" doesn't underflow the minimum value "2010-01-26".
PASS The value "2010-01-27" doesn't underflow the minimum value "2009-01-28".
PASS The value "foo" doesn't underflow the minimum value "2011-01-26".
PASS The value "" sanitized from "foo" doesn't underflow the minimum value "2011-01-26".
PASS The value "2010-01-27" undeflows the minimum value "2010-01-28".
PASS The value "9999-01-01" undeflows the minimum value "10000-12-31".
PASS The value "2010-01-27" undeflows the minimum value "2010-02-01".
......
......@@ -26,13 +26,14 @@ function checkUnderflow(value, min, disabled)
testFailed(resultText);
}
function checkNotUnderflow(value, min, disabled)
function checkNotUnderflow(value, min, disabled, sanitized)
{
input.value = value;
input.min = min;
input.disabled = !!disabled;
var underflow = input.validity.rangeUnderflow;
var resultText = 'The value "' + input.value + '" ' +
(sanitized ? 'sanitized from "' + value + '" ' : '') +
(underflow ? 'underflows' : 'doesn\'t underflow') +
' the minimum value "' + input.min + '"' + (disabled ? ' when disabled.' : '.');
if (underflow)
......@@ -41,6 +42,12 @@ function checkNotUnderflow(value, min, disabled)
testPassed(resultText);
}
function checkSanitizedValueNotUnderflow(value, max, disabled)
{
// For date types, invalid values are sanitized to "".
checkNotUnderflow(value, max, disabled, true);
}
input.type = 'date';
input.max = '';
// No underflow cases
......@@ -53,7 +60,7 @@ checkNotUnderflow('1000-01-01', '');
checkNotUnderflow('1582-10-15', '');
checkNotUnderflow('2010-01-27', '2010-01-26');
checkNotUnderflow('2010-01-27', '2009-01-28');
checkNotUnderflow('foo', '2011-01-26');
checkSanitizedValueNotUnderflow('foo', '2011-01-26');
// Underflow cases
checkUnderflow('2010-01-27', '2010-01-28');
......
......@@ -23,40 +23,40 @@ PASS "2009-11-30" is a correct valid date string.
PASS "2009-12-31" is a correct valid date string.
PASS "2008-02-29" is a correct valid date string.
PASS "2000-02-29" is a correct valid date string.
PASS " 2009-09-07 " is a correct invalid date string.
PASS "a" is a correct invalid date string.
PASS "-1-09-07" is a correct invalid date string.
PASS "0000-12-31" is a correct invalid date string.
PASS "0000-01-01" is a correct invalid date string.
PASS "275760-09-14" is a correct invalid date string.
PASS "2147483648-12-31" is a correct invalid date string.
PASS "2009/09/07" is a correct invalid date string.
PASS "20090907" is a correct invalid date string.
PASS "2009--2-07" is a correct invalid date string.
PASS "2009-00-07" is a correct invalid date string.
PASS "2009-13-07" is a correct invalid date string.
PASS "2009-xx-30" is a correct invalid date string.
PASS "2009-01-32" is a correct invalid date string.
PASS "2009-02-29" is a correct invalid date string.
PASS "2009-03-32" is a correct invalid date string.
PASS "2009-04-31" is a correct invalid date string.
PASS "2009-05-32" is a correct invalid date string.
PASS "2009-06-31" is a correct invalid date string.
PASS "2009-07-32" is a correct invalid date string.
PASS "2009-08-32" is a correct invalid date string.
PASS "2009-09-31" is a correct invalid date string.
PASS "2009-10-32" is a correct invalid date string.
PASS "2009-11-31" is a correct invalid date string.
PASS "2009-12-32" is a correct invalid date string.
PASS "2100-02-29" is a correct invalid date string.
PASS "2009-09-00" is a correct invalid date string.
PASS "2009-09-" is a correct invalid date string.
PASS "2009-09-7" is a correct invalid date string.
PASS "2009-09-001" is a correct invalid date string.
PASS "2009-09-xx" is a correct invalid date string.
PASS "2009-09" is a correct invalid date string.
PASS "2009" is a correct invalid date string.
PASS "2009-09" is a correct valid date string when disabled.
PASS " 2009-09-07 " is an invalid date string and was sanitized.
PASS "a" is an invalid date string and was sanitized.
PASS "-1-09-07" is an invalid date string and was sanitized.
PASS "0000-12-31" is an invalid date string and was sanitized.
PASS "0000-01-01" is an invalid date string and was sanitized.
PASS "275760-09-14" is an invalid date string and was sanitized.
PASS "2147483648-12-31" is an invalid date string and was sanitized.
PASS "2009/09/07" is an invalid date string and was sanitized.
PASS "20090907" is an invalid date string and was sanitized.
PASS "2009--2-07" is an invalid date string and was sanitized.
PASS "2009-00-07" is an invalid date string and was sanitized.
PASS "2009-13-07" is an invalid date string and was sanitized.
PASS "2009-xx-30" is an invalid date string and was sanitized.
PASS "2009-01-32" is an invalid date string and was sanitized.
PASS "2009-02-29" is an invalid date string and was sanitized.
PASS "2009-03-32" is an invalid date string and was sanitized.
PASS "2009-04-31" is an invalid date string and was sanitized.
PASS "2009-05-32" is an invalid date string and was sanitized.
PASS "2009-06-31" is an invalid date string and was sanitized.
PASS "2009-07-32" is an invalid date string and was sanitized.
PASS "2009-08-32" is an invalid date string and was sanitized.
PASS "2009-09-31" is an invalid date string and was sanitized.
PASS "2009-10-32" is an invalid date string and was sanitized.
PASS "2009-11-31" is an invalid date string and was sanitized.
PASS "2009-12-32" is an invalid date string and was sanitized.
PASS "2100-02-29" is an invalid date string and was sanitized.
PASS "2009-09-00" is an invalid date string and was sanitized.
PASS "2009-09-" is an invalid date string and was sanitized.
PASS "2009-09-7" is an invalid date string and was sanitized.
PASS "2009-09-001" is an invalid date string and was sanitized.
PASS "2009-09-xx" is an invalid date string and was sanitized.
PASS "2009-09" is an invalid date string and was sanitized.
PASS "2009" is an invalid date string and was sanitized.
PASS "2009-09" is an invalid date string and was sanitized while disabled.
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -11,27 +11,31 @@ description('This test aims to check for typeMismatch flag with type=date input
var i = document.createElement('input');
i.type = 'date';
function check(value, mismatchExpected, disabled)
function check(value, disabled)
{
i.value = value;
i.disabled = !!disabled;
var actual = i.validity.typeMismatch;
var didPass = actual == mismatchExpected;
var resultText = '"' + value + '" is ' + (didPass ? 'a correct ' : 'an incorrect ') + (actual ? 'invalid' : 'valid') + ' date string' + (disabled ? ' when disabled.' : '.');
if (didPass)
testPassed(resultText);
else
testFailed(resultText);
if (i.validity.typeMismatch)
testFailed('"' + value + '" had typeMismatch. This should not happen with sanitization.');
}
function shouldBeValid(value, disabled)
function shouldBeValid(value)
{
check(value, false, disabled);
check(value);
if ((value === '' && i.value === '') || (value !== '' && i.value !== ""))
testPassed('"' + value + '" is a correct valid date string.');
else
testFailed('"' + value + '" is a valid date string that failed to be set on the input.');
}
function shouldBeInvalid(value)
function shouldBeInvalid(value, disabled)
{
check(value, true);
check(value, disabled);
if (i.value === '')
testPassed('"' + value + '" is an invalid date string and was sanitized' + (disabled ? ' while disabled' : '') + '.');
else
testFailed('"' + value + '" is an invalid date string and was not sanitized' + (disabled ? ' while disabled' : '') + '.');
}
// Valid values
......@@ -92,7 +96,7 @@ shouldBeInvalid('2009-09');
shouldBeInvalid('2009');
// Disabled
shouldBeValid('2009-09', true);
shouldBeInvalid('2009-09', true);
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
......
......@@ -9,7 +9,7 @@ PASS The value "2010-01-27T12:34Z" doesn't overflow the maximum value "foo".
PASS The value "2010-01-27T12:34Z" doesn't overflow the maximum value "2010-01-27T12:34Z".
PASS The value "2010-01-27T12:34Z" doesn't overflow the maximum value "2010-01-27T12:34:56Z".
PASS The value "2010-01-27T12:34Z" doesn't overflow the maximum value "2011-01-26T12:34Z".
PASS The value "foo" doesn't overflow the maximum value "2011-01-26T12:34Z".
PASS The value "" sanitized from "foo" doesn't overflow the maximum value "2011-01-26T12:34Z".
PASS The value "2010-01-27T12:34Z" doesn't overflow the maximum value "0000-01-01T00:00Z".
PASS The value "2010-01-27T12:34Z" overflows the maximum value "2010-01-26T12:33:59.999Z".
PASS The value "9999-01-01T23:59Z" overflows the maximum value "2010-12-31T00:00Z".
......
......@@ -26,13 +26,14 @@ function checkOverflow(value, max, disabled)
testFailed(resultText);
}
function checkNotOverflow(value, max, disabled)
function checkNotOverflow(value, max, disabled, sanitized)
{
input.value = value;
input.max = max;
input.disabled = !!disabled;
var overflow = input.validity.rangeOverflow;
var resultText = 'The value "' + input.value + '" ' +
(sanitized ? 'sanitized from "' + value + '" ' : '') +
(overflow ? 'overflows' : 'doesn\'t overflow') +
' the maximum value "' + input.max + '"' + (disabled ? ' when disabled.' : '.');
if (overflow)
......@@ -41,6 +42,12 @@ function checkNotOverflow(value, max, disabled)
testPassed(resultText);
}
function checkSanitizedValueNotOverflow(value, max, disabled)
{
// For date types, invalid values are sanitized to "".
checkNotOverflow(value, max, disabled, true);
}
input.type = 'datetime';
input.min = '';
// No overflow cases
......@@ -50,7 +57,7 @@ checkNotOverflow('2010-01-27T12:34Z', 'foo');
checkNotOverflow('2010-01-27T12:34Z', '2010-01-27T12:34Z');
checkNotOverflow('2010-01-27T12:34Z', '2010-01-27T12:34:56Z');
checkNotOverflow('2010-01-27T12:34Z', '2011-01-26T12:34Z');
checkNotOverflow('foo', '2011-01-26T12:34Z');
checkSanitizedValueNotOverflow('foo', '2011-01-26T12:34Z');
checkNotOverflow('2010-01-27T12:34Z', '0000-01-01T00:00Z'); // Too small max value.
// Overflow cases
......
......@@ -10,7 +10,7 @@ PASS The value "1000-01-01T12:34Z" doesn't underflow the minimum value "".
PASS The value "1582-10-15T00:00Z" doesn't underflow the minimum value "".
PASS The value "2010-01-27T12:34Z" doesn't underflow the minimum value "2010-01-26T00:00Z".
PASS The value "2010-01-27T12:34Z" doesn't underflow the minimum value "2009-01-28T00:00Z".
PASS The value "foo" doesn't underflow the minimum value "2011-01-26T00:00Z".
PASS The value "" sanitized from "foo" doesn't underflow the minimum value "2011-01-26T00:00Z".
PASS The value "2010-01-27T12:34Z" undeflows the minimum value "2010-01-27T13:00Z".
PASS The value "9999-01-01T12:00Z" undeflows the minimum value "10000-12-31T12:00Z".
PASS The value "2010-01-27T12:00Z" undeflows the minimum value "2010-02-01T12:00Z".
......
......@@ -26,13 +26,14 @@ function checkUnderflow(value, min, disabled)
testFailed(resultText);
}
function checkNotUnderflow(value, min, disabled)
function checkNotUnderflow(value, min, disabled, sanitized)
{
input.value = value;
input.min = min;
input.disabled = !!disabled;
var underflow = input.validity.rangeUnderflow;
var resultText = 'The value "' + input.value + '" ' +
(sanitized ? 'sanitized from "' + value + '" ' : '') +
(underflow ? 'underflows' : 'doesn\'t underflow') +
' the minimum value "' + input.min + '"' + (disabled ? ' when disabled.' : '.');
if (underflow)
......@@ -41,6 +42,12 @@ function checkNotUnderflow(value, min, disabled)
testPassed(resultText);
}
function checkSanitizedValueNotUnderflow(value, max, disabled)
{
// For date types, invalid values are sanitized to "".
checkNotUnderflow(value, max, disabled, true);
}
input.type = 'datetime';
input.max = '';
// No underflow cases
......@@ -53,7 +60,7 @@ checkNotUnderflow('1000-01-01T12:34Z', '');
checkNotUnderflow('1582-10-15T00:00Z', '');
checkNotUnderflow('2010-01-27T12:34Z', '2010-01-26T00:00Z');
checkNotUnderflow('2010-01-27T12:34Z', '2009-01-28T00:00Z');
checkNotUnderflow('foo', '2011-01-26T00:00Z');
checkSanitizedValueNotUnderflow('foo', '2011-01-26T00:00Z');
// Underflow cases
checkUnderflow('2010-01-27T12:34Z', '2010-01-27T13:00Z');
......
......@@ -16,25 +16,25 @@ PASS "0001-01-01T00:00:00.000Z" is a correct valid datetime string.
PASS "0001-01-01T00:00:00.000+00:00" is a correct valid datetime string.
PASS "0001-01-01T01:30+01:30" is a correct valid datetime string.
PASS "0001-01-01T00:00+01:00" is a correct valid datetime string.
PASS " 2009-09-07T16:49Z " is a correct invalid datetime string.
PASS "2009-09-07T16:49z" is a correct invalid datetime string.
PASS "2009-09-07t16:49Z" is a correct invalid datetime string.
PASS "2009-09-07T16:49" is a correct invalid datetime string.
PASS "2009/09/07T16:49Z" is a correct invalid datetime string.
PASS "a" is a correct invalid datetime string.
PASS "-1-09-07T16:49Z" is a correct invalid datetime string.
PASS "2009-09-07T16:49+23" is a correct invalid datetime string.
PASS "2009-09-07T16:49+23:" is a correct invalid datetime string.
PASS "2009-09-07T16:49+24:00" is a correct invalid datetime string.
PASS "2009-09-07T16:49+23:60" is a correct invalid datetime string.
PASS "2009-09-07T16:49-23" is a correct invalid datetime string.
PASS "2009-09-07T16:49-23:" is a correct invalid datetime string.
PASS "2009-09-07T16:49-24:00" is a correct invalid datetime string.
PASS "2009-09-07T16:49-23:60" is a correct invalid datetime string.
PASS "0000-12-31T23:59:59Z" is a correct invalid datetime string.
PASS "2147483647-12-31T23:59-00:01" is a correct invalid datetime string.
PASS "2147483648-01-01T00:00:00Z" is a correct invalid datetime string.
PASS "invalid" is a correct valid datetime string when disabled.
PASS " 2009-09-07T16:49Z " is an invalid datetime string and was sanitized.
PASS "2009-09-07T16:49z" is an invalid datetime string and was sanitized.
PASS "2009-09-07t16:49Z" is an invalid datetime string and was sanitized.
PASS "2009-09-07T16:49" is an invalid datetime string and was sanitized.
PASS "2009/09/07T16:49Z" is an invalid datetime string and was sanitized.
PASS "a" is an invalid datetime string and was sanitized.
PASS "-1-09-07T16:49Z" is an invalid datetime string and was sanitized.
PASS "2009-09-07T16:49+23" is an invalid datetime string and was sanitized.
PASS "2009-09-07T16:49+23:" is an invalid datetime string and was sanitized.
PASS "2009-09-07T16:49+24:00" is an invalid datetime string and was sanitized.
PASS "2009-09-07T16:49+23:60" is an invalid datetime string and was sanitized.
PASS "2009-09-07T16:49-23" is an invalid datetime string and was sanitized.
PASS "2009-09-07T16:49-23:" is an invalid datetime string and was sanitized.
PASS "2009-09-07T16:49-24:00" is an invalid datetime string and was sanitized.
PASS "2009-09-07T16:49-23:60" is an invalid datetime string and was sanitized.
PASS "0000-12-31T23:59:59Z" is an invalid datetime string and was sanitized.
PASS "2147483647-12-31T23:59-00:01" is an invalid datetime string and was sanitized.
PASS "2147483648-01-01T00:00:00Z" is an invalid datetime string and was sanitized.
PASS "invalid" is an invalid datetime string and was sanitized while disabled.
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -11,27 +11,31 @@ description('This test aims to check for typeMismatch flag with type=datetime in
var i = document.createElement('input');
i.type = 'datetime';
function check(value, mismatchExpected, disabled)
function check(value, disabled)
{
i.value = value;
i.disabled = !!disabled;
var actual = i.validity.typeMismatch;
var didPass = actual == mismatchExpected;
var resultText = '"' + value + '" is ' + (didPass ? 'a correct ' : 'an incorrect ') + (actual ? 'invalid' : 'valid') + ' datetime string' + (disabled ? ' when disabled.' : '.');
if (didPass)
testPassed(resultText);
else
testFailed(resultText);
if (i.validity.typeMismatch)
testFailed('"' + value + '" had typeMismatch. This should not happen with sanitization.');
}
function shouldBeValid(value, disabled)
function shouldBeValid(value)
{
check(value, false, disabled);
check(value);
if ((value === '' && i.value === '') || (value !== '' && i.value !== ""))
testPassed('"' + value + '" is a correct valid datetime string.');
else
testFailed('"' + value + '" is a valid datetime string that failed to be set on the input.');
}
function shouldBeInvalid(value)
function shouldBeInvalid(value, disabled)
{
check(value, true);
check(value, disabled);
if (i.value === '')
testPassed('"' + value + '" is an invalid datetime string and was sanitized' + (disabled ? ' while disabled' : '') + '.');
else
testFailed('"' + value + '" is an invalid datetime string and was not sanitized' + (disabled ? ' while disabled' : '') + '.');
}
// Valid values
......@@ -70,7 +74,7 @@ shouldBeInvalid('2147483647-12-31T23:59-00:01');
shouldBeInvalid('2147483648-01-01T00:00:00Z');
// Disabled
shouldBeValid('invalid', true);
shouldBeInvalid('invalid', true);
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
......
......@@ -9,7 +9,7 @@ PASS The value "2010-01-27T12:34" doesn't overflow the maximum value "foo".
PASS The value "2010-01-27T12:34" doesn't overflow the maximum value "2010-01-27T12:34".
PASS The value "2010-01-27T12:34" doesn't overflow the maximum value "2010-01-27T12:34:56".
PASS The value "2010-01-27T12:34" doesn't overflow the maximum value "2011-01-26T12:34".
PASS The value "foo" doesn't overflow the maximum value "2011-01-26T12:34".
PASS The value "" sanitized from "foo" doesn't overflow the maximum value "2011-01-26T12:34".
PASS The value "2010-01-27T12:34" doesn't overflow the maximum value "0000-01-01T00:00".
PASS The value "2010-01-27T12:34" overflows the maximum value "2010-01-26T12:33:59.999".
PASS The value "9999-01-01T23:59" overflows the maximum value "2010-12-31T00:00".
......
......@@ -26,13 +26,14 @@ function checkOverflow(value, max, disabled)
testFailed(resultText);
}
function checkNotOverflow(value, max, disabled)
function checkNotOverflow(value, max, disabled, sanitized)
{
input.value = value;
input.max = max;
input.disabled = !!disabled;
var overflow = input.validity.rangeOverflow;
var resultText = 'The value "' + input.value + '" ' +
(sanitized ? 'sanitized from "' + value + '" ' : '') +
(overflow ? 'overflows' : 'doesn\'t overflow') +
' the maximum value "' + input.max + '"' + (disabled ? ' when disabled.' : '.');
if (overflow)
......@@ -41,6 +42,12 @@ function checkNotOverflow(value, max, disabled)
testPassed(resultText);
}
function checkSanitizedValueNotOverflow(value, max, disabled)
{
// For date types, invalid values are sanitized to "".
checkNotOverflow(value, max, disabled, true);
}
input.type = 'datetime-local';
input.min = '';
// No overflow cases
......@@ -50,7 +57,7 @@ checkNotOverflow('2010-01-27T12:34', 'foo');
checkNotOverflow('2010-01-27T12:34', '2010-01-27T12:34');
checkNotOverflow('2010-01-27T12:34', '2010-01-27T12:34:56');
checkNotOverflow('2010-01-27T12:34', '2011-01-26T12:34');
checkNotOverflow('foo', '2011-01-26T12:34');
checkSanitizedValueNotOverflow('foo', '2011-01-26T12:34');
checkNotOverflow('2010-01-27T12:34', '0000-01-01T00:00'); // Too small max value.
// Overflow cases
......
......@@ -10,7 +10,7 @@ PASS The value "1000-01-01T12:34" doesn't underflow the minimum value "".
PASS The value "1582-10-15T00:00" doesn't underflow the minimum value "".
PASS The value "2010-01-27T12:34" doesn't underflow the minimum value "2010-01-26T00:00".
PASS The value "2010-01-27T12:34" doesn't underflow the minimum value "2009-01-28T00:00".
PASS The value "foo" doesn't underflow the minimum value "2011-01-26T00:00".
PASS The value "" sanitized from "foo" doesn't underflow the minimum value "2011-01-26T00:00".
PASS The value "2010-01-27T12:34" undeflows the minimum value "2010-01-27T13:00".
PASS The value "9999-01-01T12:00" undeflows the minimum value "10000-12-31T12:00".
PASS The value "2010-01-27T12:00" undeflows the minimum value "2010-02-01T12:00".
......
......@@ -26,13 +26,14 @@ function checkUnderflow(value, min, disabled)
testFailed(resultText);
}
function checkNotUnderflow(value, min, disabled)
function checkNotUnderflow(value, min, disabled, sanitized)
{
input.value = value;
input.min = min;
input.disabled = !!disabled;
var underflow = input.validity.rangeUnderflow;
var resultText = 'The value "' + input.value + '" ' +
(sanitized ? 'sanitized from "' + value + '" ' : '') +
(underflow ? 'underflows' : 'doesn\'t underflow') +
' the minimum value "' + input.min + '"' + (disabled ? ' when disabled.' : '.');
if (underflow)
......@@ -41,6 +42,12 @@ function checkNotUnderflow(value, min, disabled)
testPassed(resultText);
}
function checkSanitizedValueNotUnderflow(value, max, disabled)
{
// For date types, invalid values are sanitized to "".
checkNotUnderflow(value, max, disabled, true);
}
input.type = 'datetime-local';
input.max = '';
// No underflow cases
......@@ -53,7 +60,7 @@ checkNotUnderflow('1000-01-01T12:34', '');
checkNotUnderflow('1582-10-15T00:00', '');
checkNotUnderflow('2010-01-27T12:34', '2010-01-26T00:00');
checkNotUnderflow('2010-01-27T12:34', '2009-01-28T00:00');
checkNotUnderflow('foo', '2011-01-26T00:00');
checkSanitizedValueNotUnderflow('foo', '2011-01-26T00:00');
// Underflow cases
checkUnderflow('2010-01-27T12:34', '2010-01-27T13:00');
......
......@@ -12,15 +12,15 @@ PASS "2009-09-07T16:49:31.123" is a correct valid datetime-local string.
PASS "2009-09-07T16:49:31.1234567890" is a correct valid datetime-local string.
PASS "275760-09-13T00:00:00.000" is a correct valid datetime-local string.
PASS "0001-01-01T00:00:00.000" is a correct valid datetime-local string.
PASS " 2009-09-07T16:49 " is a correct invalid datetime-local string.
PASS "2009-09-07t16:49" is a correct invalid datetime-local string.
PASS "2009-09-07 16:49" is a correct invalid datetime-local string.
PASS "2009/09/07T16:49" is a correct invalid datetime-local string.
PASS "a" is a correct invalid datetime-local string.
PASS "-1-09-07T16:49" is a correct invalid datetime-local string.
PASS "0000-12-31T23:59:59.999" is a correct invalid datetime-local string.
PASS "275760-09-13T00:00:00.001" is a correct invalid datetime-local string.
PASS "invalid" is a correct valid datetime-local string when disabled.
PASS " 2009-09-07T16:49 " is an invalid datetime-local string and was sanitized.
PASS "2009-09-07t16:49" is an invalid datetime-local string and was sanitized.