8000 URI by taylorotwell · Pull Request #53731 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

URI #53731

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 15 commits into from
Dec 9, 2024
Merged

URI #53731

Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add decode method to uri
  • Loading branch information
taylorotwell committed Dec 9, 2024
commit c0e0177f6737387ec9ddf7ea5f062417b4df82b0
13 changes: 13 additions & 0 deletions src/Illuminate/Support/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Str;
8000 use Illuminate\Support\Traits\Conditionable;
use Illuminate\Support\Traits\Tappable;
use League\Uri\Contracts\UriInterface;
Expand Down Expand Up @@ -293,6 +294,18 @@ public function toHtml()
return $this->value();
}

/**
* Get the decoded string representation of the URI.
*/
public function decode(): string
{
if (empty($this->query()->toArray())) {
return $this->value();
}

return Str::replace(Str::after($this->value(), '?'), $this->query()->decode(), $this->value());
}

/**
* Get the string representation of the URI.
*/
Expand Down
7 changes: 7 additions & 0 deletions tests/Support/SupportUriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,11 @@ public function test_query_strings_with_dots_can_be_replaced_or_merged_consisten
$this->assertEquals('foo.bar=baz&foo[bar]=zab', $uri->withQuery(['foo.bar' => 'zab'])->query()->decode());
$this->assertEquals('foo[bar]=zab', $uri->replaceQuery(['foo.bar' => 'zab'])->query()->decode());
}

public function test_decoding_the_entire_uri()
{
$uri = Uri::of('https://laravel.com/docs/11.x/installation')->withQuery(['tags' => ['first', 'second']]);

$this->assertEquals('https://laravel.com/docs/11.x/installation?tags[0]=first&tags[1]=second', $uri->decode());
}
}
Loading
0