Bug #81720
closedGeneralUtility::locationHeaderUrl can not handle URLs that are relative to the current protocol
100%
Description
First off it is important to know what protocol relative urls are.
A very brief description is provided by Wikipedia: https://en.wikipedia.org/wiki/URL#prurl
In fact all well-known Browsers (except IE 6 and partially IE 7-9) handle PRURLs nicely when used as links. TYPO3 in most cases also does its job when it comes to PRURLs.
So now to the actual bug which I found because EXT:dd_googlesitemap does not work with PRURLs due to it.
Reproduction:
- Install TYPO3 7.6.15 or 8.7.0 (those are the only ones that I tested)
- Get in a position to write PHP-Code (e.g. write an extension or modify the core)
- Let the url of your site be 'https://example.tld/'
- Now in your PHP-Code do
echo GeneralUtility::locationHeaderUrl('//example.tld/path/page.html')
- Visit your site via 'https://example.tld/'
My expected result:
https://example.tld/path/page.html
... because it is the absolute URL that would be generated by the browser for the given input.
Actual result:
http://example.tld//example.tld/path/page.html
This is the code of the current function locationHeaderUrl
:
$uI = parse_url($path); // relative to HOST if ($path[0] === '/') { $path = self::getIndpEnv('TYPO3_REQUEST_HOST') . $path; } elseif (!$uI['scheme']) { // No scheme either $path = self::getIndpEnv('TYPO3_REQUEST_DIR') . $path; } return $path;
Even technically the comment above the function contradicts the result. The comment is:
* Prefixes a URL used with 'header-location' with 'http://...' depending on whether it has it already. * - If already having a scheme, nothing is prepended * - If having REQUEST_URI slash '/', then prefixing 'http://[host]' (relative to host) * - Otherwise prefixed with TYPO3_REQUEST_DIR (relative to current dir / TYPO3_REQUEST_DIR)
And because the double slash at the beginning of a PRURL is not a "REQUEST_URI slash '/'", the result technically would have to be
/html/typo3///example.tld/path/page.html
... which is ridiculous. So the comment is wrong, too imho.
Files
Updated by Matteo Bonaker about 7 years ago
- Project changed from 270 to TYPO3 Core
- Category set to Miscellaneous
- TYPO3 Version set to 7
Updated by Oliver Hader about 7 years ago
- Category changed from Miscellaneous to Site Handling, Site Sets & Routing
Updated by Susanne Moog about 6 years ago
- Sprint Focus set to On Location Sprint
Updated by Gerrit Code Review about 6 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58705
Updated by Gerrit Code Review about 6 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58705
Updated by Gerrit Code Review about 6 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58705
Updated by Gerrit Code Review about 6 years ago
Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58705
Updated by Gerrit Code Review about 6 years ago
Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58705
Updated by Gerrit Code Review about 6 years ago
Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58705
Updated by Gerrit Code Review about 6 years ago
Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58705
Updated by Gerrit Code Review about 6 years ago
Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58705
Updated by Gerrit Code Review about 6 years ago
Patch set 1 for branch TYPO3_8-7 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58732
Updated by Susanne Moog about 6 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset e1ce4ed4ce3394718578f7f20b86387eb41d0315.
Updated by Gerrit Code Review about 6 years ago
- Status changed from Resolved to Under Review
Patch set 2 for branch TYPO3_8-7 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58732
Updated by Gerrit Code Review about 6 years ago
Patch set 3 for branch TYPO3_8-7 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58732
Updated by Susanne Moog about 6 years ago
- Status changed from Under Review to Resolved
Applied in changeset 7c8bc1c8518b556f6cd1e1e380dd7e87f0daecb4.