mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 828938 - Change test_input_sanitization.html type='date' handling to be like other types. r=Ms2ger
This commit is contained in:
parent
c50fe3eff1
commit
01dc822c0d
@ -41,9 +41,91 @@ var valueModeValue =
|
||||
"month", "week", "time", "datetime-local", "number", "range", "color",
|
||||
];
|
||||
|
||||
function checkDateSanitizing(element) {
|
||||
var invalidData =
|
||||
function sanitizeValue(aType, aValue)
|
||||
{
|
||||
// http://www.whatwg.org/html/#value-sanitization-algorithm
|
||||
switch (aType) {
|
||||
case "text":
|
||||
case "password":
|
||||
case "search":
|
||||
case "tel":
|
||||
return aValue.replace(/[\n\r]/g, "");
|
||||
case "url":
|
||||
case "email":
|
||||
return aValue.replace(/[\n\r]/g, "").replace(/^\s+|\s+$/g, "");
|
||||
case "number":
|
||||
return (parseFloat(aValue) + "" === aValue) ? aValue : "";
|
||||
case "date":
|
||||
function getNumbersOfDaysInMonth(aMonth, aYear) {
|
||||
if (aMonth === 2) {
|
||||
return (aYear % 400 === 0 || (aYear % 100 != 0 && aYear % 4 === 0)) ? 29 : 28;
|
||||
}
|
||||
return (aMonth === 1 || aMonth === 3 || aMonth === 5 || aMonth === 7 ||
|
||||
aMonth === 8 || aMonth === 10 || aMonth === 12) ? 31 : 30;
|
||||
}
|
||||
|
||||
var match = /^([0-9]{4,})-([0-9]{2})-([0-9]{2})$/.exec(aValue);
|
||||
if (!match) {
|
||||
return "";
|
||||
}
|
||||
var year = Number(match[1]);
|
||||
if (year === 0) {
|
||||
return "";
|
||||
}
|
||||
var month = Number(match[2]);
|
||||
if (month > 12 || month < 1) {
|
||||
return "";
|
||||
}
|
||||
var day = Number(match[3]);
|
||||
return 1 <= day && day <= getNumbersOfDaysInMonth(month, year) ? aValue : "";
|
||||
case "time":
|
||||
return "";
|
||||
case "month":
|
||||
case "week":
|
||||
case "datetime":
|
||||
case "datetime-local":
|
||||
// TODO: write the sanitize algorithm.
|
||||
ok(false);
|
||||
return "";
|
||||
case "range":
|
||||
ok(false);
|
||||
// TODO: write the sanitize algorithm.
|
||||
return "";
|
||||
case "color":
|
||||
ok(false);
|
||||
// TODO: write the sanitize algorithm.
|
||||
return "";
|
||||
default:
|
||||
return aValue;
|
||||
}
|
||||
}
|
||||
|
||||
function checkSanitizing(element)
|
||||
{
|
||||
if (element.type === 'time') {
|
||||
return;
|
||||
}
|
||||
|
||||
var testData =
|
||||
[
|
||||
// For text, password, search, tel, email:
|
||||
"\n\rfoo\n\r",
|
||||
"foo\n\rbar",
|
||||
" foo ",
|
||||
" foo\n\r bar ",
|
||||
// For url:
|
||||
"\r\n foobar \n\r",
|
||||
// For number:
|
||||
"42",
|
||||
"13.37",
|
||||
"1.234567898765432",
|
||||
// For date:
|
||||
"1970-01-01",
|
||||
"1234-12-12",
|
||||
"1234567890-01-02",
|
||||
"2012-12-31",
|
||||
"2012-02-29",
|
||||
"2000-02-29",
|
||||
"1234",
|
||||
"1234-",
|
||||
"12345",
|
||||
@ -88,88 +170,6 @@ function checkDateSanitizing(element) {
|
||||
"1234 12 12",
|
||||
];
|
||||
|
||||
var validData =
|
||||
[
|
||||
"1970-01-01",
|
||||
"1234-12-12",
|
||||
"1234567890-01-02",
|
||||
"2012-12-31",
|
||||
"2012-02-29",
|
||||
"2000-02-29",
|
||||
];
|
||||
|
||||
for (data of validData) {
|
||||
element.value = data;
|
||||
is(element.value, data, "valid date should not be sanitized");
|
||||
}
|
||||
|
||||
for (data of invalidData) {
|
||||
element.value = data;
|
||||
is(element.value, "", "invalid date should be sanitized");
|
||||
}
|
||||
}
|
||||
|
||||
function sanitizeValue(aType, aValue)
|
||||
{
|
||||
switch (aType) {
|
||||
case "text":
|
||||
case "password":
|
||||
case "search":
|
||||
case "tel":
|
||||
return aValue.replace(/[\n\r]/g, "");
|
||||
case "url":
|
||||
case "email":
|
||||
return aValue.replace(/[\n\r]/g, "").replace(/^\s+|\s+$/g, "");
|
||||
case "date":
|
||||
return "";
|
||||
case "time":
|
||||
return "";
|
||||
case "month":
|
||||
case "week":
|
||||
case "datetime":
|
||||
case "datetime-local":
|
||||
// TODO: write the sanitize algorithm.
|
||||
return "";
|
||||
case "number":
|
||||
return (parseFloat(aValue) + "" === aValue) ? aValue : "";
|
||||
case "range":
|
||||
// TODO: write the sanitize algorithm.
|
||||
return "";
|
||||
case "color":
|
||||
// TODO: write the sanitize algorithm.
|
||||
return "";
|
||||
default:
|
||||
return aValue;
|
||||
}
|
||||
}
|
||||
|
||||
function checkSanitizing(element)
|
||||
{
|
||||
if (element.type == 'date') {
|
||||
checkDateSanitizing(element);
|
||||
return;
|
||||
}
|
||||
|
||||
var testData =
|
||||
[
|
||||
// For text, password, search, tel, email:
|
||||
"\n\rfoo\n\r",
|
||||
"foo\n\rbar",
|
||||
" foo ",
|
||||
" foo\n\r bar ",
|
||||
// For url:
|
||||
"\r\n foobar \n\r",
|
||||
// For number:
|
||||
"42",
|
||||
"13.37",
|
||||
"1.234567898765432",
|
||||
];
|
||||
|
||||
// TODO: temp
|
||||
if (element.type == 'time') {
|
||||
return;
|
||||
}
|
||||
|
||||
for (value of testData) {
|
||||
element.setAttribute('value', value);
|
||||
is(element.value, sanitizeValue(type, value),
|
||||
|
Loading…
Reference in New Issue
Block a user