Bug 996055 - Prevent url.hostname from clearing the hostname. r=mcmanus

This commit is contained in:
Valentin Gosu 2014-04-23 17:45:58 +03:00
Родитель b97cc0eb86
Коммит e621efc2fa
3 изменённых файлов: 29 добавлений и 4 удалений

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

@ -347,6 +347,8 @@ URL::GetHostname(nsString& aHostname) const
void
URL::SetHostname(const nsAString& aHostname)
{
// nsStandardURL returns NS_ERROR_UNEXPECTED for an empty hostname
// The return code is silently ignored
mURI->SetHost(NS_ConvertUTF16toUTF8(aHostname));
}

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

@ -1,17 +1,16 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=887364
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 887364</title>
<title>Test URL API</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=887364">Mozilla Bug 887364</a>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=991471">Mozilla Bug 991471</a>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=996055">Mozilla Bug 996055</a>
<p id="display"></p>
<div id="content" style="display: none">
<iframe name="x" id="x"></iframe>
@ -275,5 +274,23 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=887364
}
</script>
<script>
/** Test for Bug 991471 **/
var url = new URL("http://localhost/");
url.hostname = "";
url.username = "tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt";
url.hostname = "www.mozilla.org";
url.username = "";
url.hostname = "www.mozilla.org";
is(url.href, "http://www.mozilla.org/", "No parsing error with empty host");
</script>
<script>
/** Test for Bug 996055 **/
var url = new URL("http://localhost/");
url.hostname = "";
is(url.href, "http://localhost/", "Empty hostname is ignored");
</script>
</body>
</html>

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

@ -1464,6 +1464,12 @@ nsStandardURL::SetHost(const nsACString &input)
return NS_OK;
NS_WARNING("cannot set host on no-auth url");
return NS_ERROR_UNEXPECTED;
} else {
if (flat.IsEmpty()) {
// Setting an empty hostname is not allowed for
// URLTYPE_STANDARD and URLTYPE_AUTHORITY.
return NS_ERROR_UNEXPECTED;
}
}
if (strlen(host) < flat.Length())