Skip to content

[5.6] Fix relative route URL generation with custom host formatter - #24051

Merged
taylorotwell merged 2 commits into
laravel:5.6from
staudenmeir:relative-url
Apr 29, 2018
Merged

[5.6] Fix relative route URL generation with custom host formatter#24051
taylorotwell merged 2 commits into
laravel:5.6from
staudenmeir:relative-url

Conversation

@staudenmeir

Copy link
Copy Markdown
Contributor

Generating relative route URLs doesn't work with a custom host formatter:

$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);
});

dd($url->route('plain', [], false));
// expected: '/named-route'
// actual: '/http://www.foo.org/named-route'

RouteUrlGenerator::to() tries to remove the original root, but fails because the root has been modified.

Fixes #24047.

@taylorotwell
taylorotwell merged commit 6656ed6 into laravel:5.6 Apr 29, 2018
@vlakoff

vlakoff commented Apr 30, 2018

Copy link
Copy Markdown
Contributor

That's an interesting regex… I tried this and it seems to work fine, but maybe there are some unit tests to add (for example, with a query string).

@staudenmeir

Copy link
Copy Markdown
Contributor Author

There are a lot of tests in RoutingUrlGeneratorTest::testBasicRouteGeneration().

@staudenmeir
staudenmeir deleted the relative-url branch April 30, 2018 02:06
@vlakoff

vlakoff commented Apr 30, 2018

Copy link
Copy Markdown
Contributor

Sure thing, thanks for pointing these. Apparently what I had in mind is already covered.

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

Successfully merging this pull request may close these issues.

3 participants