Skip to content

Commit

Permalink
Fix trailing paths in baseUrl bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Coulbourne committed Dec 15, 2017
1 parent b4ede02 commit 1f29ef4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/js/UrlBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ class UrlBuilder {
if (! this.absolute)
return '/';

if (!this.route.domain)
return Ziggy.baseUrl.replace(/\/?$/, '/');

let host = (this.route.domain || Ziggy.baseDomain).replace(/\/+$/, '');

if (Ziggy.basePort && (host.replace(/\/+$/, '') === Ziggy.baseDomain.replace(/\/+$/, '')))
host = host + ':' + Ziggy.basePort;
host = Ziggy.baseDomain + ':' + Ziggy.basePort;

return Ziggy.baseProtocol + '://' + host + '/';
}
Expand Down
12 changes: 11 additions & 1 deletion tests/js/test.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,5 +300,15 @@ describe('route()', function() {
'events.venues.index',
route().current()
);
})
});

it('Should still work if paths are appended to baseUrl.', function() {
let orgBaseUrl = Ziggy.baseUrl;
global.Ziggy.baseUrl = 'http://test.thing/ab/cd/';

assert.equal(
'http://test.thing/ab/cd/events/1/venues',
route('events.venues.index', 1)
);
});
});

0 comments on commit 1f29ef4

Please sign in to comment.