Bug 1422334. replaceState should update all the URI state for the entry being replaced. r=smaug

If we don't update the resultPrincipalURI, then things that examine it
(e.g. Location APIs and the URL bar) will show the wrong (pre-replaceState) URL.
I believe there is no effective difference between setting the result principal
URI to null and setting it to aNewURI here: the ultimate consumer of it is
NS_GetFinalChannelURI, which will fall back to the originalURI if it's null, and
in this case the originalURI is aNewURI.

Differential Revision: https://phabricator.services.mozilla.com/D41788

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-08-14 19:29:49 +00:00
parent 84121a15d7
commit 21c9b13b76
5 changed files with 54 additions and 0 deletions

View File

@ -11349,6 +11349,10 @@ nsresult nsDocShell::UpdateURLAndHistory(Document* aDocument, nsIURI* aNewURI,
}
newSHEntry->SetURI(aNewURI);
newSHEntry->SetOriginalURI(aNewURI);
// Setting the resultPrincipalURI to nullptr is fine here: it will cause
// NS_GetFinalChannelURI to use the originalURI as the URI, which is aNewURI
// in our case. We could also set it to aNewURI, with the same result.
newSHEntry->SetResultPrincipalURI(nullptr);
newSHEntry->SetLoadReplace(false);
}

View File

@ -0,0 +1,3 @@
<html>
<body>You should never see this</body>
</html>

View File

@ -0,0 +1,2 @@
HTTP 302 Moved Temporarily
Location: ../navigation/blank.html?x=y

View File

@ -55,6 +55,11 @@ support-files =
[test_anchor_scroll_after_document_open.html]
[test_bfcache_plus_hash.html]
[test_bug123696.html]
[test_bug1422334.html]
support-files =
bug1422334_redirect.html
bug1422334_redirect.html^headers^
!/docshell/test/navigation/blank.html
[test_bug384014.html]
[test_bug385434.html]
[test_bug387979.html]

View File

@ -0,0 +1,40 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Ensure that reload after replaceState after 3xx redirect does the right thing.</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
var ifr = document.querySelector("iframe");
var win = ifr.contentWindow;
is(win.location.href,
location.href.replace("mochitest/test_bug1422334.html",
"navigation/blank.html?x=y"),
"Should have the right location on initial load");
win.history.replaceState(null, '', win.location.pathname);
is(win.location.href,
location.href.replace("mochitest/test_bug1422334.html",
"navigation/blank.html"),
"Should have the right location after replaceState call");
ifr.onload = function() {
is(win.location.href,
location.href.replace("mochitest/test_bug1422334.html",
"navigation/blank.html"),
"Should have the right location after reload");
SimpleTest.finish();
}
win.location.reload();
})
</script>
</head>
<body>
<p id="display"><iframe src="bug1422334_redirect.html"></iframe></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
</body>
</html>