Merge pull request #6316 from halfdan/5606-subdir

Make regex for subfolder deduplication more restrictive
This commit is contained in:
Hannah Wolfe 2016-01-20 20:09:29 +00:00
commit c549914ae8
3 changed files with 18 additions and 2 deletions

View File

@ -145,6 +145,10 @@ ConfigManager.prototype.set = function (config) {
subdir = localPath === '/' ? '' : localPath;
if (!_.isEmpty(subdir)) {
this._config.slugs.protected.push(subdir.split('/').pop());
}
// Allow contentPath to be over-written by passed in config object
// Otherwise default to default content path location
contentPath = this._config.paths.contentPath || path.resolve(appRoot, 'content');

View File

@ -59,8 +59,8 @@ function urlJoin() {
// Deduplicate subdirectory
if (subdir) {
subdirRegex = new RegExp(subdir + '\/' + subdir);
url = url.replace(subdirRegex, subdir);
subdirRegex = new RegExp(subdir + '\/' + subdir + '\/');
url = url.replace(subdirRegex, subdir + '/');
}
return url;

View File

@ -113,6 +113,14 @@ describe('Config', function () {
config.paths.should.have.property('subdir', '/my/blog');
});
it('should add subdir to list of protected slugs', function () {
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
config.slugs.protected.should.containEql('blog');
configUtils.set({url: 'http://my-ghost-blog.com/my/blog'});
config.slugs.protected.should.containEql('blog');
});
it('should allow specific properties to be user defined', function () {
var contentPath = path.join(config.paths.appRoot, 'otherContent', '/'),
configFile = 'configFileDanceParty.js';
@ -269,6 +277,10 @@ describe('Config', function () {
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
config.urlFor(testContext, testData).should.equal('/blog/short-and-sweet/');
config.urlFor(testContext, testData, true).should.equal('http://my-ghost-blog.com/blog/short-and-sweet/');
testData.post.url = '/blog-one/';
config.urlFor(testContext, testData).should.equal('/blog/blog-one/');
config.urlFor(testContext, testData, true).should.equal('http://my-ghost-blog.com/blog/blog-one/');
});
it('should return url for a tag when asked for', function () {