Bug 854812 - Do not allow email with sub-domains or tld starting or ending with a '-' in <input type='email'>. r=mounir,khuey

This commit is contained in:
Alice Lieutier 2013-04-11 00:05:07 +02:00
Родитель 86a6c2bb6c
Коммит 144cf2e3aa
2 изменённых файлов: 26 добавлений и 10 удалений

Просмотреть файл

@ -5693,9 +5693,10 @@ HTMLInputElement::IsValidEmailAddress(const nsAString& aValue)
NS_ERROR("nsIIDNService isn't present!");
}
// If the email address is empty, begins with a '@' or ends with a '.',
// we know it's invalid.
if (length == 0 || value[0] == '@' || value[length-1] == '.') {
// If the email address is empty, begins with an '@'
// or ends with a '.' or '-', we know it's invalid.
if (length == 0 || value[0] == '@' || value[length-1] == '.' ||
value[length-1] == '-') {
return false;
}
@ -5713,14 +5714,13 @@ HTMLInputElement::IsValidEmailAddress(const nsAString& aValue)
}
}
// There is no domain name (or it's one-character long),
// that's not a valid email address.
// If there is no domain name, that's not a valid email address.
if (++i >= length) {
return false;
}
// The domain name can't begin with a dot.
if (value[i] == '.') {
// The domain name can't begin with a dot or a dash.
if (value[i] == '.' || value[i] == '-') {
return false;
}
@ -5729,7 +5729,12 @@ HTMLInputElement::IsValidEmailAddress(const nsAString& aValue)
PRUnichar c = value[i];
if (c == '.') {
// A dot can't follow a dot.
// A dot can't follow a dot or a dash.
if (value[i-1] == '.' || value[i-1] == '-') {
return false;
}
} else if (c == '-'){
// A dash can't follow a dot.
if (value[i-1] == '.') {
return false;
}

Просмотреть файл

@ -3,6 +3,7 @@
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=555559
https://bugzilla.mozilla.org/show_bug.cgi?id=668817
https://bugzilla.mozilla.org/show_bug.cgi?id=854812
-->
<head>
<title>Test for &lt;input type='email'&gt; validity</title>
@ -12,6 +13,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=668817
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=555559">Mozilla Bug 555559</a>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=668817">Mozilla Bug 668817</a>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=854812">Mozilla Bug 854812</a>
<p id="display"></p>
<div id="content" style="display: none">
<form>
@ -110,6 +112,16 @@ var values = [
// Long strings with UTF-8.
[ 'this.is.email.should.be.longer.than.sixty.four.characters.föö@mözillä.tld', true ],
[ 'this-is-email-should-be-longer-than-sixty-four-characters-föö@mözillä.tld', true, true ],
// The domains labels (sub-domains or tld) can't start or finish with a '-'
[ 'foo@foo-bar', true ],
[ 'foo@-foo', false ],
[ 'foo@foo-.bar', false ],
[ 'foo@-.-', false ],
[ 'foo@fo-o.bar', true ],
[ 'foo@fo-o.-bar', false ],
[ 'foo@fo-o.bar-', false ],
[ 'foo@fo-o.-', false ],
[ 'foo@fo--o', true ],
];
// Multiple values, we don't check e-mail validity, only multiple stuff.
@ -161,9 +173,8 @@ for (c of illegalCharacters) {
legalCharacters = "abcdefghijklmnopqrstuvwxyz";
legalCharacters += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
legalCharacters += "0123456789";
legalCharacters += "-";
// Add domain legal characters (except '.' because it's special).
// Add domain legal characters (except '.' and '-' because they are special).
for (c of legalCharacters) {
values.push(["foo@foo.bar" + c, true]);
}