whatwg / html

HTML Standard
https://html.spec.whatwg.org/multipage/
Other
8.01k stars 2.62k forks source link

How should the meta refresh URL resolve? #7332

Open danny0838 opened 2 years ago

danny0838 commented 2 years ago

When a web page https://example.com/page has the following content, what should the meta refresh target be for each case?

case 1

<base target="subdir/">
<meta http-equiv="refresh" content="0; url=target.html">

In Firefox 94, it's https://example.com/target.html.

In Chromium 95, it's https://example.com/subdir/target.html.

case 2

<meta http-equiv="refresh" content="0; url=target.html">
<base target="subdir/">

In Firefox 94, it's https://example.com/target.html.

In Chromium 95, it's https://example.com/target.html.

case 3

<meta http-equiv="refresh" content="1; url=target.html">
<base target="subdir/">

In Firefox 94, it's https://example.com/target.html.

In Chromium 95, it's https://example.com/subdir/target.html.


It seems that Firefox resolves a meta refresh using the initial base URL.

Chromium resolves a meta refresh using the current base URL. However, if the time of a meta refresh is 0, Chromium resolves the meta refresh at the time the tag is loaded, and, as a result, all following <base>s are not taken into account.

What is the expected behavior by the web standard? I have read https://html.spec.whatwg.org/#attr-meta-http-equiv-refresh, but failed to understand what should happen in such cases.

annevk commented 2 years ago

So the "shared declarative refresh steps" algorithm runs when the meta element is inserted. In step 11.11 of that algorithm it parses the URL relative to the document (that ends up using the current base URL). Later that URL is used to navigate, potentially after a delay.

That would mean that Chrome is correct for case 1 and Firefox for case 3.

Would you be willing to create web-platform-tests for these scenarios?

danny0838 commented 2 years ago

What do you mean "create web-platform-tests"?

annevk commented 2 years ago

See https://github.com/web-platform-tests/wpt. It's a project that hosts cross-browser tests to foster interoperability between browsers.

danny0838 commented 2 years ago

Sorry. Not familiar with that. Maybe some long long long future day...

freddyrios commented 2 months ago

Another resolution difference: <meta http-equiv="refresh" content="0; url=/target.html">

Updated with the confirmed difference:

Opening the local file path in the browser (instead of via a web server):

Firefox 128: ignores/rejects the redirect Edge 126 (Chromium) redirects to localDirContainingThePage/target.html

Original (wrong / did not reproduced with isolated example):

Opening the page in a web server.

Firefox 128: ignores/rejects the redirect Edge 126 (Chromium) redirects to https://example.com/target.html