summaryrefslogtreecommitdiff
path: root/classes/urlhelper.php
diff options
context:
space:
mode:
authorwn_ <[email protected]>2021-11-15 03:28:17 +0000
committerwn_ <[email protected]>2021-11-15 03:28:17 +0000
commitfb208bb136de79b5d84b3343493eef635cf0269a (patch)
tree0fc6efa54f82988b5bf62ea8db19a99d1edfd3cd /classes/urlhelper.php
parent41b4eef504d0d910472e9213672699d758c89cb7 (diff)
Fix a PHPStan warning in 'UrlHelper::rewrite_relative()'.
Diffstat (limited to 'classes/urlhelper.php')
-rw-r--r--classes/urlhelper.php14
1 files changed, 12 insertions, 2 deletions
diff --git a/classes/urlhelper.php b/classes/urlhelper.php
index 5d0d80a41..91e1d4822 100644
--- a/classes/urlhelper.php
+++ b/classes/urlhelper.php
@@ -53,12 +53,22 @@ class UrlHelper {
* @param string $owner_element Owner element tag name (i.e. "a") (optional)
* @param string $owner_attribute Owner attribute (i.e. "href") (optional)
*
- * @return string Absolute URL
+ * @return false|string Absolute URL or false on failure (either during URL parsing or validation)
*/
public static function rewrite_relative($base_url, $rel_url, string $owner_element = "", string $owner_attribute = "") {
-
$rel_parts = parse_url($rel_url);
+ /**
+ * If parse_url failed to parse $rel_url return false to match the current "invalid thing" behavior
+ * of UrlHelper::validate().
+ *
+ * TODO: There are many places where a string return value is assumed. We should either update those
+ * to account for the possibility of failure, or look into updating this function's return values.
+ */
+ if ($rel_parts === false) {
+ return false;
+ }
+
if (!empty($rel_parts['host']) && !empty($rel_parts['scheme'])) {
return self::validate($rel_url);