Skip to content

Commit 11424b4

Browse files
tobias-93willdurand
authored andcommitted
Fix regression introduced by fix for Symfony 3, check for undefined schemes key (#288)
* Fix regression introduced by fix for Symfony 3, check for undefined schemes key * Fix tests and add test for new way of scheme definition * Add additional check in schemes usage * Remove duplicate check in router.js and revert changes to existing tests
1 parent f91e652 commit 11424b4

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

Resources/js/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ fos.Router.prototype.generate = function(name, opt_params, absolute) {
241241
url = this.context_.base_url + url;
242242
if (goog.object.containsKey(route.requirements, "_scheme") && this.getScheme() != route.requirements["_scheme"]) {
243243
url = route.requirements["_scheme"] + "://" + (host || this.getHost()) + url;
244-
} else if (goog.object.containsKey(route, "schemes") && this.getScheme() != route.schemes[0]) {
244+
} else if (goog.object.containsKey(route, "schemes") && typeof route.schemes[0] !== "undefined" && this.getScheme() != route.schemes[0]) {
245245
url = route.schemes[0] + "://" + (host || this.getHost()) + url;
246246
} else if (host && this.getHost() !== host) {
247247
url = this.getScheme() + "://" + host + url;

Resources/js/router.test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ function testGenerateUsesHostWhenTheSameSchemeRequirementGiven() {
7878
assertEquals('http://otherhost/foo/bar', router.generate('homepage'));
7979
}
8080

81+
function testGenerateUsesHostWhenTheSameSchemeGiven() {
82+
var router = new fos.Router({base_url: '/foo', host: "localhost", scheme: "http"}, {
83+
homepage: {
84+
tokens: [['text', '/bar']],
85+
defaults: {},
86+
requirements: {},
87+
hosttokens: [['text', 'otherhost']],
88+
schemes: ['http'],
89+
methods: []
90+
}
91+
});
92+
93+
assertEquals('http://otherhost/foo/bar', router.generate('homepage'));
94+
}
95+
8196
function testGenerateUsesHostWhenAnotherSchemeRequirementGiven() {
8297
var router = new fos.Router({base_url: '/foo', host: "localhost", scheme: "http"}, {
8398
homepage: {
@@ -91,6 +106,21 @@ function testGenerateUsesHostWhenAnotherSchemeRequirementGiven() {
91106
assertEquals('https://otherhost/foo/bar', router.generate('homepage'));
92107
}
93108

109+
function testGenerateUsesHostWhenAnotherSchemeGiven() {
110+
var router = new fos.Router({base_url: '/foo', host: "localhost", scheme: "http"}, {
111+
homepage: {
112+
tokens: [['text', '/bar']],
113+
defaults: {},
114+
requirements: {},
115+
hosttokens: [['text', 'otherhost']],
116+
schemes: ['https'],
117+
methods: []
118+
}
119+
});
120+
121+
assertEquals('https://otherhost/foo/bar', router.generate('homepage'));
122+
}
123+
94124
function testGenerateSupportsHostPlaceholders() {
95125
var router = new fos.Router({base_url: '/foo', host: "localhost", scheme: "http"}, {
96126
homepage: {
@@ -165,6 +195,21 @@ function testGenerateUsesAbsoluteUrlWhenSchemeRequirementGiven() {
165195
assertEquals('http://localhost/foo/bar', router.generate('homepage', [], true));
166196
}
167197

198+
function testGenerateUsesAbsoluteUrlWhenSchemeGiven() {
199+
var router = new fos.Router({base_url: '/foo', host: "localhost", scheme: "http"}, {
200+
homepage: {
201+
tokens: [['text', '/bar']],
202+
defaults: {},
203+
requirements: {},
204+
hosttokens: [],
205+
schemes: ['http'],
206+
methods: []
207+
}
208+
});
209+
210+
assertEquals('http://localhost/foo/bar', router.generate('homepage', [], true));
211+
}
212+
168213
function testGenerateWithOptionalTrailingParam() {
169214
var router = new fos.Router({base_url: ''}, {
170215
posts: {

Resources/public/js/router.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)