mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Bug 1082723 - Add IPv6 delimiters to nsLocation::GetHostname and Link::GetHostname r=smaug
This commit is contained in:
parent
74a360e504
commit
f4b976820f
@ -2184,6 +2184,12 @@ public:
|
||||
*/
|
||||
static uint64_t GetInnerWindowID(nsIRequest* aRequest);
|
||||
|
||||
/**
|
||||
* If the hostname for aURI is an IPv6 it encloses it in brackets,
|
||||
* otherwise it just outputs the hostname in aHost.
|
||||
*/
|
||||
static void GetHostOrIPv6WithBrackets(nsIURI* aURI, nsAString& aHost);
|
||||
|
||||
private:
|
||||
static bool InitializeEventTable();
|
||||
|
||||
|
@ -361,13 +361,7 @@ Link::GetHostname(nsAString &_hostname, ErrorResult& aError)
|
||||
return;
|
||||
}
|
||||
|
||||
nsAutoCString host;
|
||||
nsresult rv = uri->GetHost(host);
|
||||
// Note that failure to get the host from the URI is not necessarily a bad
|
||||
// thing. Some URIs do not have a host.
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
CopyUTF8toUTF16(host, _hostname);
|
||||
}
|
||||
nsContentUtils::GetHostOrIPv6WithBrackets(uri, _hostname);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -6998,3 +6998,23 @@ nsContentUtils::GetInnerWindowID(nsIRequest* aRequest)
|
||||
|
||||
return inner ? inner->WindowID() : 0;
|
||||
}
|
||||
|
||||
void
|
||||
nsContentUtils::GetHostOrIPv6WithBrackets(nsIURI* aURI, nsAString& aHost)
|
||||
{
|
||||
aHost.Truncate();
|
||||
nsAutoCString hostname;
|
||||
nsresult rv = aURI->GetHost(hostname);
|
||||
if (NS_FAILED(rv)) { // Some URIs do not have a host
|
||||
return;
|
||||
}
|
||||
|
||||
if (hostname.FindChar(':') != -1) { // Escape IPv6 address
|
||||
MOZ_ASSERT(!hostname.Length() ||
|
||||
(hostname[0] !='[' && hostname[hostname.Length() - 1] != ']'));
|
||||
hostname.Insert('[', 0);
|
||||
hostname.Append(']');
|
||||
}
|
||||
|
||||
CopyUTF8toUTF16(hostname, aHost);
|
||||
}
|
||||
|
@ -382,17 +382,7 @@ void
|
||||
URL::GetHostname(nsString& aHostname, ErrorResult& aRv) const
|
||||
{
|
||||
aHostname.Truncate();
|
||||
nsAutoCString tmp;
|
||||
nsresult rv = mURI->GetHost(tmp);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (tmp.FindChar(':') != -1) { // Escape IPv6 address
|
||||
MOZ_ASSERT(!tmp.Length() ||
|
||||
(tmp[0] !='[' && tmp[tmp.Length() - 1] != ']'));
|
||||
tmp.Insert('[', 0);
|
||||
tmp.Append(']');
|
||||
}
|
||||
CopyUTF8toUTF16(tmp, aHostname);
|
||||
}
|
||||
nsContentUtils::GetHostOrIPv6WithBrackets(mURI, aHostname);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -407,18 +407,9 @@ nsLocation::GetHostname(nsAString& aHostname)
|
||||
aHostname.Truncate();
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult result;
|
||||
|
||||
result = GetURI(getter_AddRefs(uri), true);
|
||||
|
||||
GetURI(getter_AddRefs(uri), true);
|
||||
if (uri) {
|
||||
nsAutoCString host;
|
||||
|
||||
result = uri->GetHost(host);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
AppendUTF8toUTF16(host, aHostname);
|
||||
}
|
||||
nsContentUtils::GetHostOrIPv6WithBrackets(uri, aHostname);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
Loading…
Reference in New Issue
Block a user