Bug 1295636 - SetHostPort should reset the port if the host parameter does not have a port number. r=valentin, r=smaug

--HG--
extra : rebase_source : 2e63afd5708c55810206f9bc47b6f078a0824400
This commit is contained in:
Dragana Damjanovic 2016-08-17 23:25:00 -04:00
Родитель 983fd9fa51
Коммит 67635a6600
7 изменённых файлов: 51 добавлений и 6 удалений

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

@ -126,6 +126,12 @@ nsNullPrincipalURI::SetHostPort(const nsACString &aHost)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsNullPrincipalURI::SetHostAndPort(const nsACString &aHost)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsNullPrincipalURI::GetOriginCharset(nsACString &_charset)
{

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

@ -947,12 +947,8 @@ nsHTMLDocument::SetDomain(const nsAString& aDomain, ErrorResult& rv)
return;
}
// If the old uri had a port number and the new domain does not have,
// SetHostPort will not reset the port number of the old uri, it will be
// kept. Here we want to reset the port number, so we need to do it manually.
newURI->SetPort(-1);
rv2 = newURI->SetHostPort(NS_ConvertUTF16toUTF8(aDomain));
// We use SetHostAndPort because we want to reset the port number if needed.
rv2 = newURI->SetHostAndPort(NS_ConvertUTF16toUTF8(aDomain));
if (NS_FAILED(rv2)) {
rv.Throw(rv2);
return;

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

@ -328,6 +328,12 @@ nsMozIconURI::SetHostPort(const nsACString& aHostPort)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsMozIconURI::SetHostAndPort(const nsACString& aHostPort)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsMozIconURI::GetHost(nsACString& aHost)
{

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

@ -384,6 +384,12 @@ nsJARURI::SetHostPort(const nsACString &aHostPort)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsJARURI::SetHostAndPort(const nsACString &aHostPort)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsJARURI::GetHost(nsACString &aHost)
{

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

@ -123,10 +123,19 @@ interface nsIURI : nsISupports
/**
* The host:port (or simply the host, if port == -1).
*
* If this attribute is set to a value that only has a host part, the port
* will not be reset. To reset the port as well use setHostAndPort.
*
* Characters are NOT escaped.
*/
attribute AUTF8String hostPort;
/**
* This function will always set a host and a port. If the port part is
* empty, the value of the port will be set to the default value.
*/
void setHostAndPort(in AUTF8String hostport);
/**
* The host is the internet domain name to which this URI refers. It could
* be an IPv4 (or IPv6) address literal. If supported, it could be a

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

@ -315,6 +315,14 @@ nsSimpleURI::SetHostPort(const nsACString &result)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsSimpleURI::SetHostAndPort(const nsACString &result)
{
NS_ENSURE_STATE(mMutable);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsSimpleURI::GetHost(nsACString &result)
{

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

@ -1775,6 +1775,8 @@ nsStandardURL::FindHostLimit(nsACString::const_iterator& aStart,
}
}
// If aValue only has a host part and no port number, the port
// will not be reset!!!
NS_IMETHODIMP
nsStandardURL::SetHostPort(const nsACString &aValue)
{
@ -1845,6 +1847,18 @@ nsStandardURL::SetHostPort(const nsACString &aValue)
return NS_OK;
}
// This function is different than SetHostPort in that the port number will be
// reset as well if aValue parameter does not contain a port port number.
NS_IMETHODIMP
nsStandardURL::SetHostAndPort(const nsACString &aValue)
{
// Reset the port and than call SetHostPort. SetHostPort does not reset
// the port number.
nsresult rv = SetPort(-1);
NS_ENSURE_SUCCESS(rv, rv);
return SetHostPort(aValue);
}
NS_IMETHODIMP
nsStandardURL::SetHost(const nsACString &input)
{