Skip to content

Commit 0dfb6d3

Browse files
vikaspotluri123acburdine
authored andcommitted
fix(config): disallow URLs ending with /ghost
1 parent 0f00c03 commit 0dfb6d3

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

lib/commands/config/advanced.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ const knownMailServices = [
2121
module.exports = {
2222
url: {
2323
description: 'Blog URL with protocol E.g. http://loveghost.com',
24-
validate: value => validator.isURL(value, {require_protocol: true}) ||
25-
'Invalid URL. Your URL should include a protocol, E.g. http://my-ghost-blog.com',
24+
validate: (value) => {
25+
const urlValidation = validator.isURL(value, {require_protocol: true});
26+
const endsWithGhost = new RegExp('(?:/ghost/?)$', 'i');
27+
if (urlValidation) {
28+
return (!endsWithGhost.test(value)) || 'Ghost doesn\'t support running in a path that ends with `ghost`';
29+
}
30+
31+
return 'Invalid URL. Your URL should include a protocol, E.g. http://my-ghost-blog.com';
32+
},
2633
transform: value => value.toLowerCase(),
2734
type: 'string',
2835
group: 'Ghost Options:'

lib/commands/config/index.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,15 @@ class ConfigCommand extends Command {
103103
name: 'url',
104104
message: 'Enter your blog URL:',
105105
default: this.instance.config.get('url', 'http://localhost:2368'),
106-
validate: (value) => validator.isURL(value, {require_protocol: true}) ||
107-
'Invalid URL. Your URL should include a protocol, E.g. http://my-ghost-blog.com'
106+
validate: (value) => {
107+
const urlValidation = validator.isURL(value, {require_protocol: true});
108+
const endsWithGhost = new RegExp('(?:/ghost/?)$', 'i');
109+
if (urlValidation) {
110+
return (!endsWithGhost.test(value)) || 'Ghost doesn\'t support running in a path that ends with `ghost`';
111+
}
112+
113+
return 'Invalid URL. Your URL should include a protocol, E.g. http://my-ghost-blog.com';
114+
}
108115
});
109116
}
110117

test/unit/commands/config-spec.js

+2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ describe('Unit: Command > Config', function () {
190190
expect(result[0].name).to.equal('url');
191191
expect(result[0].validate('http://localhost:2368')).to.be.true;
192192
expect(result[0].validate('notaurl')).to.match(/Invalid URL/);
193+
expect(result[0].validate('https://localhost:2368/ghost')).to.match(/path that ends with `ghost`/);
193194
});
194195

195196
it('returns db prompts if db arg not provided', function () {
@@ -471,6 +472,7 @@ describe('Unit: Command > Config', function () {
471472
expect(advancedOptions.url.validate('http://localhost:2368')).to.be.true;
472473
expect(advancedOptions.url.validate('localhost:2368')).to.match(/Invalid URL/);
473474
expect(advancedOptions.url.validate('not even remotely a URL')).to.match(/Invalid URL/);
475+
expect(advancedOptions.url.validate('http://localhost:2368/ghost')).to.match(/path that ends with `ghost`/);
474476

475477
// Check transform function
476478
expect(advancedOptions.url.transform('http://MyUpperCaseUrl.com')).to.equal('http://myuppercaseurl.com');

0 commit comments

Comments
 (0)