From a20fa6a3a93475d6707f1a1aeedc4edc692935d9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 11 Jan 2019 19:27:56 -0500 Subject: [PATCH] Add ensureQueryParameter method to Util\Strings --- src/Util/Strings.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Util/Strings.php b/src/Util/Strings.php index 473774b71..a11ac2fd5 100644 --- a/src/Util/Strings.php +++ b/src/Util/Strings.php @@ -312,4 +312,20 @@ class Strings { return (strcasecmp(self::normaliseLink($a), self::normaliseLink($b)) === 0); } + + + /** + * Ensures the provided URI has its query string punctuation in order. + * + * @param string $uri + * @return string + */ + public static function ensureQueryParameter($uri) + { + if (strpos($uri, '?') === false && ($pos = strpos($uri, '&')) !== false) { + $uri = substr($uri, 0, $pos) . '?' . substr($uri, $pos + 1); + } + + return $uri; + } }