From 990e1b91bbb680098efb609dced64fafcd6512d3 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Wed, 9 Jul 2025 22:09:18 -0700 Subject: [PATCH] fix: omit : and @ if user and pass are empty So, unparsing should not end up with https://:@appwrite.io just because user and pass are empty strings. --- src/Appwrite/URL/URL.php | 4 ++-- tests/unit/URL/URLTest.php | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/URL/URL.php b/src/Appwrite/URL/URL.php index a511c8dc13..49e95929e7 100644 --- a/src/Appwrite/URL/URL.php +++ b/src/Appwrite/URL/URL.php @@ -68,9 +68,9 @@ class URL $parts['user'] = isset($url['user']) ? $url['user'] : ''; - $parts['pass'] = isset($url['pass']) ? ':' . $url['pass'] : ''; + $parts['pass'] = !empty($url['pass']) ? ':' . $url['pass'] : ''; - $parts['pass'] = ($parts['user'] || $parts['pass']) ? $parts['pass'] . '@' : ''; + $parts['pass'] = ($parts['user'] || !empty($parts['pass'])) ? $parts['pass'] . '@' : ''; $parts['path'] = isset($url['path']) ? $url['path'] : ''; diff --git a/tests/unit/URL/URLTest.php b/tests/unit/URL/URLTest.php index 93415ee20b..ceca1c6304 100644 --- a/tests/unit/URL/URLTest.php +++ b/tests/unit/URL/URLTest.php @@ -95,6 +95,19 @@ class URLTest extends TestCase $this->assertIsString($url); $this->assertEquals('https://eldad:fux@appwrite.io/#bottom', $url); + + $url = URL::unparse([ + 'scheme' => 'https', + 'user' => '', + 'pass' => '', + 'host' => 'appwrite.io', + 'port' => null, + 'path' => '', + 'fragment' => '', + ]); + + $this->assertIsString($url); + $this->assertEquals('https://appwrite.io/#', $url); } public function testParseQuery(): void