mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2025-12-15 23:05:55 +00:00
add unit tests for rewrite_relative_url and fix a number of bugs in it
This commit is contained in:
committed by
Andrew Dolgov
parent
24eb4c780f
commit
f679105cb2
@@ -7074,6 +7074,14 @@
|
||||
return $parts['scheme'] . "://" . $parts['host'] . $parts['path'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a (possibly) relative URL to a absolute one.
|
||||
*
|
||||
* @param string $url Base URL (i.e. from where the document is)
|
||||
* @param string $rel_url Possibly relative URL in the document
|
||||
*
|
||||
* @return string Absolute URL
|
||||
*/
|
||||
function rewrite_relative_url($url, $rel_url) {
|
||||
if (strpos($rel_url, "://") !== false) {
|
||||
return $rel_url;
|
||||
@@ -7086,8 +7094,15 @@
|
||||
|
||||
} else {
|
||||
$parts = parse_url($url);
|
||||
|
||||
$parts['path'] = dirname($parts['path']) . "/$rel_url";
|
||||
if (!isset($parts['path'])) {
|
||||
$parts['path'] = '/';
|
||||
}
|
||||
$dir = $parts['path'];
|
||||
if (substr($dir, -1) !== '/') {
|
||||
$dir = dirname($parts['path']);
|
||||
$dir !== '/' && $dir .= '/';
|
||||
}
|
||||
$parts['path'] = $dir . $rel_url;
|
||||
|
||||
return build_url($parts);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user