Bug 1192666 - Emit '[]' around origin strings for ipv6 origins, r=ehsan

This commit is contained in:
Michael Layzell 2015-08-09 18:47:20 -04:00
Родитель dc95876ffe
Коммит 274d644ee1
2 изменённых файлов: 18 добавлений и 3 удалений

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

@ -111,7 +111,7 @@ nsPrincipal::GetOriginForURI(nsIURI* aURI, nsACString& aOrigin)
return NS_ERROR_FAILURE;
}
nsAutoCString hostPort;
nsAutoCString host;
// chrome: URLs don't have a meaningful origin, so make
// sure we just get the full spec for them.
@ -120,10 +120,10 @@ nsPrincipal::GetOriginForURI(nsIURI* aURI, nsACString& aOrigin)
bool isChrome;
nsresult rv = origin->SchemeIs("chrome", &isChrome);
if (NS_SUCCEEDED(rv) && !isChrome) {
rv = origin->GetAsciiHost(hostPort);
rv = origin->GetAsciiHost(host);
// Some implementations return an empty string, treat it as no support
// for asciiHost by that implementation.
if (hostPort.IsEmpty()) {
if (host.IsEmpty()) {
rv = NS_ERROR_FAILURE;
}
}
@ -159,6 +159,15 @@ nsPrincipal::GetOriginForURI(nsIURI* aURI, nsACString& aOrigin)
}
if (NS_SUCCEEDED(rv) && !isChrome) {
nsAutoCString hostPort;
if (host.FindChar(':') != -1) {
hostPort.Assign("[");
hostPort.Append(host);
hostPort.Append("]");
} else {
hostPort.Assign(host);
}
if (port != -1) {
hostPort.Append(':');
hostPort.AppendInt(port, 10);

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

@ -47,6 +47,12 @@ function run_test() {
var nullPrin = Cu.getObjectPrincipal(new Cu.Sandbox(null));
do_check_true(/^moz-nullprincipal:\{([0-9]|[a-z]|\-){36}\}$/.test(nullPrin.origin));
checkOriginAttributes(nullPrin);
var ipv6Prin = ssm.createCodebasePrincipal(makeURI('https://[2001:db8::ff00:42:8329]:123'), {});
do_check_eq(ipv6Prin.origin, 'https://[2001:db8::ff00:42:8329]:123');
checkOriginAttributes(ipv6Prin);
var ipv6NPPrin = ssm.createCodebasePrincipal(makeURI('https://[2001:db8::ff00:42:8329]'), {});
do_check_eq(ipv6NPPrin.origin, 'https://[2001:db8::ff00:42:8329]');
checkOriginAttributes(ipv6NPPrin);
var ep = ssm.createExpandedPrincipal([exampleCom, nullPrin, exampleOrg]);
checkOriginAttributes(ep);
checkCrossOrigin(exampleCom, exampleOrg);