Skip to content

Commit c8e30f0

Browse files
committed
Make regex for subfolder deduplication more restrictive
- Add subdir to protected slugs - Fix regex for subfolder deduplication fixes #5605
1 parent 5e2523a commit c8e30f0

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

core/server/config/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ ConfigManager.prototype.set = function (config) {
143143

144144
subdir = localPath === '/' ? '' : localPath;
145145

146+
if (!_.isEmpty(subdir)) {
147+
this._config.slugs.protected.push(subdir.split('/').pop());
148+
}
149+
146150
// Allow contentPath to be over-written by passed in config object
147151
// Otherwise default to default content path location
148152
contentPath = this._config.paths.contentPath || path.resolve(appRoot, 'content');

core/server/config/url.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ function urlJoin() {
5151

5252
// Deduplicate subdirectory
5353
if (subdir) {
54-
subdirRegex = new RegExp(subdir + '\/' + subdir);
55-
url = url.replace(subdirRegex, subdir);
54+
subdirRegex = new RegExp(subdir + '\/' + subdir + '\/');
55+
url = url.replace(subdirRegex, subdir + '/');
5656
}
5757

5858
return url;

core/test/unit/config_spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ describe('Config', function () {
112112
config.paths.should.have.property('subdir', '/my/blog');
113113
});
114114

115+
it('should add subdir to list of protected slugs', function () {
116+
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
117+
config.slugs.protected.should.containEql('blog');
118+
119+
configUtils.set({url: 'http://my-ghost-blog.com/my/blog'});
120+
config.slugs.protected.should.containEql('blog');
121+
});
122+
115123
it('should allow specific properties to be user defined', function () {
116124
var contentPath = path.join(config.paths.appRoot, 'otherContent', '/'),
117125
configFile = 'configFileDanceParty.js';
@@ -268,6 +276,10 @@ describe('Config', function () {
268276
configUtils.set({url: 'http://my-ghost-blog.com/blog'});
269277
config.urlFor(testContext, testData).should.equal('/blog/short-and-sweet/');
270278
config.urlFor(testContext, testData, true).should.equal('http://my-ghost-blog.com/blog/short-and-sweet/');
279+
280+
testData.post.url = '/blog-one/';
281+
config.urlFor(testContext, testData).should.equal('/blog/blog-one/');
282+
config.urlFor(testContext, testData, true).should.equal('http://my-ghost-blog.com/blog/blog-one/');
271283
});
272284

273285
it('should return url for a tag when asked for', function () {

0 commit comments

Comments
 (0)