FriendsOfSymfony / FOSJsRoutingBundle

A pretty nice way to expose your Symfony routing to client applications.
1.48k stars 261 forks source link

Scheme missing in generated URL #377

Open KhorneHoly opened 4 years ago

KhorneHoly commented 4 years ago

Hi,

I've encountered an issue with the 2.5.3 release, after upgrading it from 2.3.1.

If we're generating an URL, the returned URL is missing the leading HTTP/HTTPS scheme. With that, the generated URL will be appended to the current URL from the browser instead of correctly redirect to the generated URL.

Example:

url = Routing.generate('base', {
    'itemId': 1234
});
console.log(url);

test.domain.de/base/1234

instead of

http://test.domain.de/base/1234

If I set the generated URL to a link or just redirect via javascript

window.location.href = url;

The browser will try to reach this url:

http://test.domain.de/base/test.domain.de/base/1234

Reverting back to release to 2.3.1 or manually add the missing schema fixed the issue for now.

window.location.href = schema + "//" + url;

Thank you for creating and maintaining this bundle, it's highly appreciated.

metalmini commented 4 years ago

Same problem here

YoannChabert commented 4 years ago

I got the problem when i upgraded this package :

"symfony/serializer": "^5.0.4" to "symfony/serializer": "^5.0.5"

With JsRouting in 2.5

@metalmini @KhorneHoly

Edit : I also deleted the content of bundles in my public dir

GKFX commented 4 years ago

Not sure the expected behaviour is being described quite right. I believe the sample code

url = Routing.generate('base', {
    'itemId': 1234
});
console.log(url);

should result in no domain part at all, i.e. /base/1234. There's a final argument to generate the full URL,

url = Routing.generate('base', {
    'itemId': 1234
}, true);
console.log(url);

should give http://test.domain.de/base/1234.

This seems to be an intermittent fault. Having just downgraded then re-upgraded, the bug went away, and even prior to that the bug was only active if (in my project) I ran yarn encore production rather than yarn encore dev, for example.