Skip to content

Commit 1e1ed42

Browse files
authored
[12.x] Uri prevent empty query string (#55146)
* Add broken example * Fallback to `null` when query string is empty to remove it
1 parent b3dc56c commit 1e1ed42

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Illuminate/Support/Uri.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public function withQuery(array $query, bool $merge = true): static
235235
}
236236
}
237237

238-
return new static($this->uri->withQuery(Arr::query($newQuery)));
238+
return new static($this->uri->withQuery(Arr::query($newQuery) ?: null));
239239
}
240240

241241
/**

tests/Support/SupportUriTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,12 @@ public function test_with_query_if_missing()
188188
],
189189
], $uri->query()->all());
190190
}
191+
192+
public function test_with_query_prevents_empty_query_string()
193+
{
194+
$uri = Uri::of('https://laravel.com');
195+
196+
$this->assertEquals('https://laravel.com', (string) $uri);
197+
$this->assertEquals('https://laravel.com', (string) $uri->withQuery([]));
198+
}
191199
}

0 commit comments

Comments
 (0)