0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Don't pass external urls through createUrl

refs #4852, refs #4862, refs #4541

- fixes urlFor for the combination of an external url and a blog using a subdirectory
This commit is contained in:
Hannah Wolfe 2015-02-12 23:09:12 +00:00
parent f073e10221
commit eaee9369e8
2 changed files with 14 additions and 4 deletions

View file

@ -161,10 +161,6 @@ function urlFor(context, data, absolute) {
// mismatch in http/https etc, force absolute
urlPath = '/' + urlPath.split(hostname)[1];
absolute = true;
} else { // not hosted on this ghost instance, so
// urls with protocols are already absolute
// and otherwise respect the passed in value
absolute = (urlPath.indexOf('://') === -1) && absolute;
}
}
// other objects are recognised but not yet supported
@ -173,6 +169,11 @@ function urlFor(context, data, absolute) {
urlPath = knownPaths[context] || '/';
}
// This url already has a protocol so is likely an external url to be returned
if (urlPath && urlPath.indexOf('://') !== -1) {
return urlPath;
}
return createUrl(urlPath, absolute, secure);
}

View file

@ -142,4 +142,13 @@ describe('{{url}} helper', function () {
should.exist(rendered);
rendered.should.equal('http://testurl.com/blog/xyzzy');
});
it('external urls should be retained in a nav context with subdir', function () {
utils.overrideConfig({url: 'http://testurl.com/blog'});
var rendered = helpers.url.call(
{url: 'http://casper.website/baz', label: 'Baz', slug: 'baz', current: true},
{hash: {absolute: 'true'}});
should.exist(rendered);
rendered.should.equal('http://casper.website/baz');
});
});