Bug 1154812. Fix location.pathname to return the right thing in workers. r=baku

This commit is contained in:
Boris Zbarsky 2015-04-15 16:32:53 -04:00
parent f334c48f31
commit bb5dfb44a0
8 changed files with 19 additions and 34 deletions

View File

@ -7139,22 +7139,27 @@ nsContentUtils::GetInnerWindowID(nsIRequest* aRequest)
}
void
nsContentUtils::GetHostOrIPv6WithBrackets(nsIURI* aURI, nsAString& aHost)
nsContentUtils::GetHostOrIPv6WithBrackets(nsIURI* aURI, nsCString& aHost)
{
aHost.Truncate();
nsAutoCString hostname;
nsresult rv = aURI->GetHost(hostname);
nsresult rv = aURI->GetHost(aHost);
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(']');
if (aHost.FindChar(':') != -1) { // Escape IPv6 address
MOZ_ASSERT(!aHost.Length() ||
(aHost[0] !='[' && aHost[aHost.Length() - 1] != ']'));
aHost.Insert('[', 0);
aHost.Append(']');
}
}
void
nsContentUtils::GetHostOrIPv6WithBrackets(nsIURI* aURI, nsAString& aHost)
{
nsAutoCString hostname;
GetHostOrIPv6WithBrackets(aURI, hostname);
CopyUTF8toUTF16(hostname, aHost);
}

View File

@ -2282,6 +2282,7 @@ public:
* otherwise it just outputs the hostname in aHost.
*/
static void GetHostOrIPv6WithBrackets(nsIURI* aURI, nsAString& aHost);
static void GetHostOrIPv6WithBrackets(nsIURI* aURI, nsCString& aHost);
/*
* Call the given callback on all remote children of the given top-level

View File

@ -3996,17 +3996,16 @@ WorkerPrivateParent<Derived>::SetBaseURI(nsIURI* aBaseURI)
mLocationInfo.mHref.Truncate();
}
if (NS_FAILED(aBaseURI->GetHost(mLocationInfo.mHostname))) {
mLocationInfo.mHostname.Truncate();
}
nsContentUtils::GetHostOrIPv6WithBrackets(aBaseURI, mLocationInfo.mHostname);
if (NS_FAILED(aBaseURI->GetPath(mLocationInfo.mPathname))) {
nsCOMPtr<nsIURL> url(do_QueryInterface(aBaseURI));
if (!url || NS_FAILED(url->GetFilePath(mLocationInfo.mPathname))) {
mLocationInfo.mPathname.Truncate();
}
nsCString temp;
nsCOMPtr<nsIURL> url(do_QueryInterface(aBaseURI));
if (url && NS_SUCCEEDED(url->GetQuery(temp)) && !temp.IsEmpty()) {
mLocationInfo.mSearch.Assign('?');
mLocationInfo.mSearch.Append(temp);

View File

@ -1,5 +0,0 @@
[members.html]
type: testharness
[members of WorkerLocation]
expected: FAIL

View File

@ -1,5 +0,0 @@
[redirect.html]
type: testharness
[location with a worker in separate file that redirects]
expected: FAIL

View File

@ -1,5 +0,0 @@
[setting-members.html]
type: testharness
[setting members of WorkerLocation]
expected: FAIL

View File

@ -1,5 +0,0 @@
[worker-separate-file.html]
type: testharness
[location with a worker in separate file]
expected: FAIL

View File

@ -9,7 +9,7 @@
<script>
async_test(function() {
var worker = new Worker('helper-redirect.py?fail');
worker.onmessage = this.step_func(function(e) {
worker.onmessage = this.step_func_done(function(e) {
assert_equals(e.data[0], location.href.replace(/\/[^\/]+$/, '/post-location-members.js?a'));
assert_equals(e.data[1], location.protocol);
assert_equals(e.data[2], location.host);