Skip to content

[12.x] Uri prevent empty query string #55146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public function withQuery(array $query, bool $merge = true): static
}
}

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

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/Support/SupportUriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,12 @@ public function test_with_query_if_missing()
],
], $uri->query()->all());
}

public function test_with_query_prevents_empty_query_string()
{
$uri = Uri::of('https://laravel.com');

$this->assertEquals('https://laravel.com', (string) $uri);
$this->assertEquals('https://laravel.com', (string) $uri->withQuery([]));
}
}
Loading