0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Merge pull request #6938 from ErisDS/issue-6937

Guard for currentUrl being undefined in navigation
This commit is contained in:
Sebastian Gierlinger 2016-06-09 10:01:01 +02:00
commit 924c9963b4
2 changed files with 16 additions and 0 deletions

View file

@ -42,6 +42,10 @@ navigation = function (options) {
// strips trailing slashes and compares urls
function _isCurrentUrl(href, currentUrl) {
if (!currentUrl) {
return false;
}
var strippedHref = href.replace(/\/+$/, ''),
strippedCurrentUrl = currentUrl.replace(/\/+$/, '');
return strippedHref === strippedCurrentUrl;

View file

@ -70,6 +70,18 @@ describe('{{navigation}} helper', function () {
rendered.string.should.be.equal('');
});
it('can handle relativeUrl not being set (e.g. for images/assets)', function () {
var singleItem = {label: 'Foo', url: '/foo'},
rendered;
delete optionsData.data.root.relativeUrl;
optionsData.data.blog.navigation = [singleItem];
rendered = helpers.navigation(optionsData);
rendered.string.should.containEql('li');
rendered.string.should.containEql('nav-foo');
rendered.string.should.containEql('/foo');
});
it('can render one item', function () {
var singleItem = {label: 'Foo', url: '/foo'},
testUrl = 'href="' + configUtils.config.url + '/foo"',