mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-16 22:04:36 +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);
|
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:
|
private:
|
||||||
static bool InitializeEventTable();
|
static bool InitializeEventTable();
|
||||||
|
|
||||||
|
@ -361,13 +361,7 @@ Link::GetHostname(nsAString &_hostname, ErrorResult& aError)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoCString host;
|
nsContentUtils::GetHostOrIPv6WithBrackets(uri, _hostname);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -6998,3 +6998,23 @@ nsContentUtils::GetInnerWindowID(nsIRequest* aRequest)
|
|||||||
|
|
||||||
return inner ? inner->WindowID() : 0;
|
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
|
URL::GetHostname(nsString& aHostname, ErrorResult& aRv) const
|
||||||
{
|
{
|
||||||
aHostname.Truncate();
|
aHostname.Truncate();
|
||||||
nsAutoCString tmp;
|
nsContentUtils::GetHostOrIPv6WithBrackets(mURI, aHostname);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -407,18 +407,9 @@ nsLocation::GetHostname(nsAString& aHostname)
|
|||||||
aHostname.Truncate();
|
aHostname.Truncate();
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> uri;
|
nsCOMPtr<nsIURI> uri;
|
||||||
nsresult result;
|
GetURI(getter_AddRefs(uri), true);
|
||||||
|
|
||||||
result = GetURI(getter_AddRefs(uri), true);
|
|
||||||
|
|
||||||
if (uri) {
|
if (uri) {
|
||||||
nsAutoCString host;
|
nsContentUtils::GetHostOrIPv6WithBrackets(uri, aHostname);
|
||||||
|
|
||||||
result = uri->GetHost(host);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result)) {
|
|
||||||
AppendUTF8toUTF16(host, aHostname);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user