Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 23, 2020
1 parent 42c67a1 commit a1e741a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
19 changes: 7 additions & 12 deletions src/Illuminate/Http/RedirectResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,28 +146,23 @@ public function withErrors($provider, $key = 'default')
}

/**
* Add fragment identifier to the url.
* Add a fragment identifier to the URL.
*
* @param string $fragmentIdentifier
* @param string $fragment
* @return $this
*/
public function withFragmentIdentifier($fragmentIdentifier)
public function withFragment($fragment)
{
// Remove any existing fragment identifier
$this->withoutFragmentIdentifier();

// Strip superfluous "#" from the beginning of the fragment identifier
$fragmentIdentifier = Str::after($fragmentIdentifier, '#');

return $this->setTargetUrl($this->getTargetUrl()."#$fragmentIdentifier");
return $this->withoutFragment()
->setTargetUrl($this->getTargetUrl().'#'.Str::after($fragment, '#'));
}

/**
* Remove any fragment identifier from the response url.
* Remove any fragment identifier from the response URL.
*
* @return $this
*/
public function withoutFragmentIdentifier()
public function withoutFragment()
{
return $this->setTargetUrl(Str::before($this->getTargetUrl(), '#'));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Http/HttpRedirectResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public function testFragmentIdentifierOnRedirect()
{
$response = new RedirectResponse('foo.bar');

$response->withFragmentIdentifier('foo');
$response->withFragment('foo');
$this->assertSame('foo', parse_url($response->getTargetUrl(), PHP_URL_FRAGMENT));

$response->withFragmentIdentifier('#bar');
$response->withFragment('#bar');
$this->assertSame('bar', parse_url($response->getTargetUrl(), PHP_URL_FRAGMENT));

$response->withoutFragmentIdentifier();
$response->withoutFragment();
$this->assertNull(parse_url($response->getTargetUrl(), PHP_URL_FRAGMENT));
}

Expand Down

0 comments on commit a1e741a

Please sign in to comment.