Skip to content
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

Generating URI for route fails with custom host formatter #24047

Closed
imbrish opened this issue Apr 29, 2018 · 0 comments
Closed

Generating URI for route fails with custom host formatter #24047

imbrish opened this issue Apr 29, 2018 · 0 comments

Comments

@imbrish
Copy link
Contributor

imbrish commented Apr 29, 2018

  • Laravel Version: 5.7, 5.6, 5.5 (and earlier?)
  • PHP Version: any
  • Database Driver & Version: any

Description:

Generating relative URLs for routes doesn't work with custom host formatter.

Steps To Reproduce:

public function testGenerateRelativeUrlForRouteWithHostFormatter()
{
    $url = new UrlGenerator(
        $routes = new RouteCollection,
        $request = Request::create('http://www.foo.com/')
    );

    $routes->add(
        new Route(['GET'], '/named-route', ['as' => 'plain'])
    );

    $url->formatHostUsing(function ($host) {
        return str_replace('foo.com', 'foo.org', $host);
    });

    $this->assertEquals('http://www.foo.org/named-route', $url->route('plain'));
    $this->assertEquals('/named-route', $url->route('plain', [], false));
}

Second assertion fails:

Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'/named-route'
+'/http://www.foo.org/named-route'

Reason

RouteUrlGenerator tries to remove original root from uri and fails, because root has been modified.

@imbrish imbrish changed the title [5.7] Generating URI for route fails with custom host formatter Generating URI for route fails with custom host formatter Apr 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant