Skip to content

Commit

Permalink
fix(setup): strip undesirable characters out of DB name (#486)
Browse files Browse the repository at this point in the history
no issue
- normalize default db name for mysql
  • Loading branch information
kieranajp authored and acburdine committed Oct 8, 2017
1 parent 7b6c8cc commit 5878002
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/commands/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ class ConfigCommand extends Command {
}

if (!argv.dbname) {
const sanitizedDirName = path.basename(process.cwd()).replace(/[^a-zA-Z0-9_]+/g, '_');
prompts.push({
type: 'input',
name: 'dbname',
message: 'Enter your Ghost database name:',
default: this.instance.config.get('database.connection.database', `ghost_${this.system.environment}_${path.basename(process.cwd())}`)
default: this.instance.config.get('database.connection.database', `ghost_${this.system.environment}_${sanitizedDirName}`),
validate: (val) => !/[^a-zA-Z0-9_]/.test(val) || 'MySQL database names may consist of only alphanumeric characters and underscores.'
});
}
}
Expand Down
7 changes: 6 additions & 1 deletion test/unit/commands/config-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ describe('Unit: Command > Config', function () {
expect(passprompt).to.be.ok;
expect(passprompt.message).to.match(/skip to keep current/);

expect(result.find(prompt => prompt.name === 'dbname')).to.be.ok;
const nameprompt = result.find(prompt => prompt.name === 'dbname');
expect(nameprompt).to.be.ok;
expect(nameprompt.validate('example123')).to.be.true;
expect(nameprompt.validate('example123.com')).to.match(/consist of only alpha/);
expect(nameprompt.validate('example-123')).to.match(/consist of only alpha/);
expect(nameprompt.validate('example!!!')).to.match(/consist of only alpha/);
});

it('doesn\'t return dbhost prompt if dbhost provided', function () {
Expand Down

0 comments on commit 5878002

Please sign in to comment.