description("This test aims to check for typeMismatch flag and sanitization with type=email input fields.");
var i = document.createElement('input');
i.type = 'email';
function emailCheck(value, expectedValue, expectedMismatch, multiple)
{
i.value = value;
i.multiple = !!multiple;
var mismatch = i.validity.typeMismatch;
var mismatchPass = mismatch == expectedMismatch;
var sanitizePass = i.value == expectedValue;
var mismatchResult = '"' + value + '" is a ' + (mismatch ? 'invalid' : 'valid') + ' email address' + (multiple ? ' list. ' : '. ');
var sanitizeResult = 'It was sanitized to "' + i.value + '"' + (sanitizePass ? '.' : ', but should be sanitized to "' + expectedValue + '"');
var result = mismatchResult;
if (value != expectedValue || !sanitizePass)
result += sanitizeResult;
if (mismatchPass && sanitizePass)
testPassed(result);
else
testFailed(result);
}
var expectValid = false;
var expectInvalid = true;
var multiple = true;
debug("Valid single addresses when 'multiple' attribute is not set.");
emailCheck("[email protected]", "[email protected]", expectValid);
emailCheck("[email protected]", "[email protected]", expectValid);
emailCheck("[email protected]", "[email protected]", expectValid);
emailCheck("[email protected]", "[email protected]", expectValid);
emailCheck("a/[email protected]", "a/[email protected]", expectValid);
emailCheck("{}@domain.com", "{}@domain.com", expectValid);
emailCheck("m*'!%@something.sa", "m*'!%@something.sa", expectValid);
emailCheck("tu!!7n7.ad##[email protected]", "tu!!7n7.ad##[email protected]", expectValid);
emailCheck("%@com.com", "%@com.com", expectValid);
emailCheck("!#$%&'*+/=?^_`{|}[email protected]", "!#$%&'*+/=?^_`{|}[email protected]", expectValid);
emailCheck("[email protected]", "[email protected]", expectValid);
emailCheck("[email protected]", "[email protected]", expectValid);
emailCheck("[email protected]", "[email protected]", expectValid);
emailCheck("somebody@example", "somebody@example", expectValid);
emailCheck("\[email protected]\u000A", "[email protected]", expectValid);
emailCheck("\[email protected]\u000D", "[email protected]", expectValid);
emailCheck("a\[email protected]", "[email protected]", expectValid);
emailCheck("a\[email protected]", "[email protected]", expectValid);
emailCheck("", "", expectValid);
emailCheck(" ", "", expectValid);
emailCheck(" [email protected]", "[email protected]", expectValid);
emailCheck("[email protected] ", "[email protected]", expectValid);
emailCheck(" [email protected] ", "[email protected]", expectValid);
emailCheck("\[email protected]\u0020", "[email protected]", expectValid);
emailCheck("\[email protected]\u0009", "[email protected]", expectValid);
emailCheck("\[email protected]\u000C", "[email protected]", expectValid);
debug("Invalid single addresses when 'multiple' attribute is not set.");
emailCheck("invalid:[email protected]", "invalid:[email protected]", expectInvalid);
emailCheck("@somewhere.com", "@somewhere.com", expectInvalid);
emailCheck("example.com", "example.com", expectInvalid);
emailCheck("@@example.com", "@@example.com", expectInvalid);
emailCheck("a [email protected]", "a [email protected]", expectInvalid);
emailCheck("[email protected]", "[email protected]", expectInvalid);
emailCheck("a\b@c", "a\b@c", expectInvalid);
emailCheck("[email protected].", "[email protected].", expectInvalid);
emailCheck("\"\"test\blah\"\"@example.com", "\"\"test\blah\"\"@example.com", expectInvalid);
emailCheck("\"testblah\"@example.com", "\"testblah\"@example.com", expectInvalid);
emailCheck("[email protected]@", "[email protected]@", expectInvalid);
emailCheck("someone@somewhere_com", "someone@somewhere_com", expectInvalid);
emailCheck("someone@some:where.com", "someone@some:where.com", expectInvalid);
emailCheck(".", ".", expectInvalid);
emailCheck("F/s/f/a@feo+re.com", "F/s/f/a@feo+re.com", expectInvalid);
emailCheck("some+long+email+address@some+host-weird-/looking.com", "some+long+email+address@some+host-weird-/looking.com", expectInvalid);
emailCheck("a @p.com", "a @p.com", expectInvalid);
emailCheck("a\[email protected]", "a\[email protected]", expectInvalid);
emailCheck("a\[email protected]", "a\[email protected]", expectInvalid);
emailCheck("a\[email protected]", "a\[email protected]", expectInvalid);
emailCheck("a\[email protected]", "a\[email protected]", expectInvalid);
emailCheck("a\[email protected]", "a\[email protected]", expectInvalid);
emailCheck("a\[email protected]", "a\[email protected]", expectInvalid);
emailCheck("[email protected]", "[email protected]", expectInvalid);
emailCheck("[email protected]", "[email protected]", expectInvalid);
emailCheck("[email protected]", "[email protected]", expectInvalid);
emailCheck("[email protected]", "[email protected]", expectInvalid);
debug("Valid single addresses when 'multiple' attribute is set.");
emailCheck("[email protected]", "[email protected]", expectValid, multiple);
emailCheck("[email protected]", "[email protected]", expectValid, multiple);
emailCheck("[email protected]", "[email protected]", expectValid, multiple);
emailCheck("[email protected]", "[email protected]", expectValid, multiple);
emailCheck("a/[email protected]", "a/[email protected]", expectValid, multiple);
emailCheck("{}@domain.com", "{}@domain.com", expectValid, multiple);
emailCheck("m*'!%@something.sa", "m*'!%@something.sa", expectValid, multiple);
emailCheck("tu!!7n7.ad##[email protected]", "tu!!7n7.ad##[email protected]", expectValid, multiple);
emailCheck("%@com.com", "%@com.com", expectValid, multiple);
emailCheck("!#$%&'*+/=?^_`{|}[email protected]", "!#$%&'*+/=?^_`{|}[email protected]", expectValid, multiple);
emailCheck("[email protected]", "[email protected]", expectValid, multiple);
emailCheck("[email protected]", "[email protected]", expectValid, multiple);
emailCheck("[email protected]", "[email protected]", expectValid, multiple);
emailCheck("somebody@example", "somebody@example", expectValid, multiple);
emailCheck("\[email protected]\u0020", "[email protected]", expectValid, multiple);
emailCheck("\[email protected]\u0009", "[email protected]", expectValid, multiple);
emailCheck("\[email protected]\u000A", "[email protected]", expectValid, multiple);
emailCheck("\[email protected]\u000C", "[email protected]", expectValid, multiple);
emailCheck("\[email protected]\u000D", "[email protected]", expectValid, multiple);
emailCheck("a\[email protected]", "[email protected]", expectValid, multiple);
emailCheck("a\[email protected]", "[email protected]", expectValid, multiple);
emailCheck("", "", expectValid, multiple);
emailCheck(" ", "", expectValid, multiple);
emailCheck(" [email protected]", "[email protected]", expectValid, multiple);
emailCheck("[email protected] ", "[email protected]", expectValid, multiple);
emailCheck(" [email protected] ", "[email protected]", expectValid, multiple);
debug("Invalid single addresses when 'multiple' attribute is set.");
emailCheck("invalid:[email protected]", "invalid:[email protected]", expectInvalid, multiple);
emailCheck("@somewhere.com", "@somewhere.com", expectInvalid, multiple);
emailCheck("example.com", "example.com", expectInvalid, multiple);
emailCheck("@@example.com", "@@example.com", expectInvalid, multiple);
emailCheck("a [email protected]", "a [email protected]", expectInvalid, multiple);
emailCheck("[email protected]", "[email protected]", expectInvalid, multiple);
emailCheck("a\b@c", "a\b@c", expectInvalid, multiple);
emailCheck("[email protected].", "[email protected].", expectInvalid, multiple);
emailCheck("\"\"test\blah\"\"@example.com", "\"\"test\blah\"\"@example.com", expectInvalid, multiple);
emailCheck("\"testblah\"@example.com", "\"testblah\"@example.com", expectInvalid, multiple);
emailCheck("[email protected]@", "[email protected]@", expectInvalid, multiple);
emailCheck("someone@somewhere_com", "someone@somewhere_com", expectInvalid, multiple);
emailCheck("someone@some:where.com", "someone@some:where.com", expectInvalid, multiple);
emailCheck(".", ".", expectInvalid, multiple);
emailCheck("F/s/f/a@feo+re.com", "F/s/f/a@feo+re.com", expectInvalid, multiple);
emailCheck("some+long+email+address@some+host-weird-/looking.com", "some+long+email+address@some+host-weird-/looking.com", expectInvalid, multiple);
emailCheck("\[email protected]\u000B", "\[email protected]\u000B", expectInvalid, multiple);
emailCheck("\[email protected]\u2003", "\[email protected]\u2003", expectInvalid, multiple);
emailCheck("\[email protected]\u3000", "\[email protected]\u3000", expectInvalid, multiple);
emailCheck("a @p.com", "a @p.com", expectInvalid, multiple);
emailCheck("a\[email protected]", "a\[email protected]", expectInvalid, multiple);
emailCheck("a\[email protected]", "a\[email protected]", expectInvalid, multiple);
emailCheck("a\[email protected]", "a\[email protected]", expectInvalid, multiple);
emailCheck("a\[email protected]", "a\[email protected]", expectInvalid, multiple);
emailCheck("a\[email protected]", "a\[email protected]", expectInvalid, multiple);
emailCheck("a\[email protected]", "a\[email protected]", expectInvalid, multiple);
emailCheck("[email protected]", "[email protected]", expectInvalid, multiple);
emailCheck("[email protected]", "[email protected]", expectInvalid, multiple);
emailCheck("[email protected]", "[email protected]", expectInvalid, multiple);
emailCheck("[email protected]", "[email protected]", expectInvalid, multiple);
debug("Valid multiple addresses when 'multiple' attribute is set.");
emailCheck("[email protected],[email protected],[email protected],a/[email protected],[email protected]", "[email protected],[email protected],[email protected],a/[email protected],[email protected]", expectValid, multiple);
emailCheck("tu!!7n7.ad##[email protected],F/s/f/[email protected],m*'@a.b", "tu!!7n7.ad##[email protected],F/s/f/[email protected],m*'@a.b", expectValid, multiple);
emailCheck(" [email protected],[email protected]", "[email protected],[email protected]", expectValid, multiple);
emailCheck("[email protected] ,[email protected]", "[email protected],[email protected]", expectValid, multiple);
emailCheck("[email protected], [email protected]", "[email protected],[email protected]", expectValid, multiple);
emailCheck("[email protected],[email protected] ", "[email protected],[email protected]", expectValid, multiple);
emailCheck(" [email protected] , [email protected] ", "[email protected],[email protected]", expectValid, multiple);
emailCheck("\[email protected]\u0020,\[email protected]\u0020", "[email protected],[email protected]", expectValid, multiple);
emailCheck("\[email protected]\u0009,\[email protected]\u0009", "[email protected],[email protected]", expectValid, multiple);
emailCheck("\[email protected]\u000A,\[email protected]\u000A", "[email protected],[email protected]", expectValid, multiple);
emailCheck("\[email protected]\u000C,\[email protected]\u000C", "[email protected],[email protected]", expectValid, multiple);
emailCheck("\[email protected]\u000D,\[email protected]\u000D", "[email protected],[email protected]", expectValid, multiple);
debug("Invalid multiple addresses when 'multiple' attribute is set.");
emailCheck("[email protected],[email protected],a@b,a/b@c,[email protected]", "[email protected],[email protected],a@b,a/b@c,[email protected]", expectInvalid, multiple);
emailCheck("some+long+email+address@some+host:weird-/looking.com,F/s/f/a@feo+re.com,,m*'@'!%", "some+long+email+address@some+host:weird-/looking.com,F/s/f/a@feo+re.com,,m*'@'!%", expectInvalid, multiple);
emailCheck(" a @p.com , [email protected] ", "a @p.com,[email protected]", expectInvalid, multiple);
emailCheck(" [email protected] , b @p.com ", "[email protected],b @p.com", expectInvalid, multiple);
emailCheck("\[email protected]\u000B,\[email protected]\u000B", "\[email protected]\u000B,\[email protected]\u000B", expectInvalid, multiple);
emailCheck("\[email protected]\u2003,\[email protected]\u2003", "\[email protected]\u2003,\[email protected]\u2003", expectInvalid, multiple);
emailCheck("\[email protected]\u3000,\[email protected]\u3000", "\[email protected]\u3000,\[email protected]\u3000", expectInvalid, multiple);
emailCheck(",,", ",,", expectInvalid, multiple);
emailCheck(" ,,", ",,", expectInvalid, multiple);
emailCheck(", ,", ",,", expectInvalid, multiple);
emailCheck(",, ", ",,", expectInvalid, multiple);
emailCheck(" , , ", ",,", expectInvalid, multiple);
emailCheck("\u0020,\u0020,\u0020", ",,", expectInvalid, multiple);
emailCheck("\u0009,\u0009,\u0009", ",,", expectInvalid, multiple);
emailCheck("\u000A,\u000A,\u000A", ",,", expectInvalid, multiple);
emailCheck("\u000B,\u000B,\u000B", "\u000B,\u000B,\u000B", expectInvalid, multiple);
emailCheck("\u000C,\u000C,\u000C", ",,", expectInvalid, multiple);
emailCheck("\u000D,\u000D,\u000D", ",,", expectInvalid, multiple);
emailCheck("\u2003,\u2003,\u2003", "\u2003,\u2003,\u2003", expectInvalid, multiple);
emailCheck("\u3000,\u3000,\u3000", "\u3000,\u3000,\u3000", expectInvalid, multiple);