summaryrefslogtreecommitdiff
path: root/functions.php
diff options
context:
space:
mode:
authorChristian Weiske <[email protected]>2010-11-10 23:09:03 +0100
committerAndrew Dolgov <[email protected]>2010-11-11 09:44:05 +0300
commitf679105cb2adc6de3e41527830fa0bfde36324d1 (patch)
tree0b8d3afbb9419559fedb5f00143eceb106ce4d68 /functions.php
parent24eb4c780f531363e90fe2d8248d50189dcb6b38 (diff)
add unit tests for rewrite_relative_url and fix a number of bugs in it
Diffstat (limited to 'functions.php')
-rw-r--r--functions.php19
1 files changed, 17 insertions, 2 deletions
diff --git a/functions.php b/functions.php
index 96fa19224..a52dafddd 100644
--- a/functions.php
+++ b/functions.php
@@ -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);
}