mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Merge pull request #5056 from ianlopshire/master
url helper breaks subdomains
This commit is contained in:
commit
cb2f0c5dee
2 changed files with 26 additions and 2 deletions
|
@ -156,10 +156,14 @@ function urlFor(context, data, absolute) {
|
|||
urlPath = data.nav.url;
|
||||
baseUrl = (secure && ghostConfig.urlSSL) ? ghostConfig.urlSSL : ghostConfig.url;
|
||||
hostname = baseUrl.split('//')[1] + ghostConfig.paths.subdir;
|
||||
if (urlPath.indexOf(hostname) > -1) {
|
||||
if (urlPath.indexOf(hostname) > -1 && urlPath.indexOf('.' + hostname) === -1) {
|
||||
// make link relative to account for possible
|
||||
// mismatch in http/https etc, force absolute
|
||||
urlPath = '/' + urlPath.split(hostname)[1];
|
||||
// do not do so if link is a subdomain of blog url
|
||||
urlPath = urlPath.split(hostname)[1];
|
||||
if (urlPath.substring(0, 1) !== '/') {
|
||||
urlPath = '/' + urlPath;
|
||||
}
|
||||
absolute = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -254,6 +254,26 @@ describe('Config', function () {
|
|||
config.urlFor(testContext, testData).should.equal('/blog/tag/kitchen-sink/');
|
||||
config.urlFor(testContext, testData, true).should.equal('http://my-ghost-blog.com/blog/tag/kitchen-sink/');
|
||||
});
|
||||
|
||||
it('should return a url for a nav item when asked for it', function () {
|
||||
var testContext = 'nav',
|
||||
testData;
|
||||
|
||||
config.set({url: 'http://my-ghost-blog.com', urlSSL: 'https://my-ghost-blog.com'});
|
||||
|
||||
testData = {nav: {url: 'http://my-ghost-blog.com/short-and-sweet/'}};
|
||||
config.urlFor(testContext, testData).should.equal('http://my-ghost-blog.com/short-and-sweet/');
|
||||
|
||||
testData = {nav: {url: 'http://my-ghost-blog.com/short-and-sweet/'}, secure: true};
|
||||
config.urlFor(testContext, testData).should.equal('https://my-ghost-blog.com/short-and-sweet/');
|
||||
|
||||
testData = {nav: {url: 'http://sub.my-ghost-blog.com/'}};
|
||||
config.urlFor(testContext, testData).should.equal('http://sub.my-ghost-blog.com/');
|
||||
|
||||
config.set({url: 'http://my-ghost-blog.com/blog'});
|
||||
testData = {nav: {url: 'http://my-ghost-blog.com/blog/short-and-sweet/'}};
|
||||
config.urlFor(testContext, testData).should.equal('http://my-ghost-blog.com/blog/short-and-sweet/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('urlPathForPost', function () {
|
||||
|
|
Loading…
Add table
Reference in a new issue