Skip to content

Commit 6a9dd3c

Browse files
MaximDevoirgr2m
authored andcommitted
Partially sanitize data by escaping double-quote characters (#81)
Fixes #74
1 parent 953de0c commit 6a9dd3c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

bin/create-probot-app.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,28 @@ const { generate } = require('egad')
1010
const kebabCase = require('lodash.kebabcase')
1111
const camelCase = require('lodash.camelcase')
1212
const chalk = require('chalk')
13+
const jsesc = require('jsesc')
1314
const spawn = require('cross-spawn')
1415
const stringifyAuthor = require('stringify-author')
1516
const { guessEmail, guessAuthor, guessGitHubUsername } = require('conjecture')
1617
const validatePackageName = require('validate-npm-package-name')
1718

19+
/**
20+
* Partially sanitizes keys by escaping double-quotes.
21+
*
22+
* @param {Object} object The object to mutate.
23+
* @param {String[]} keys The keys on `object` to sanitize.
24+
*/
25+
function sanitizeBy(object, keys) {
26+
keys.forEach(key => {
27+
if (key in object) {
28+
object[key] = jsesc(object[key], {
29+
quotes: 'double'
30+
})
31+
}
32+
})
33+
}
34+
1835
program
1936
.usage('[options] [destination]')
2037
.option('-n, --appName <app-name>', 'App name')
@@ -133,6 +150,8 @@ inquirer.prompt(prompts)
133150
answers.template = program.template || answers.template
134151

135152
// TODO: clean that up into nicer object combinging
153+
154+
sanitizeBy(answers, ['author', 'description'])
136155

137156
if (!templates.includes(answers.template)) {
138157
console.log(chalk.red(`Please use an existing use case template: ${templates.join(', ')}`))

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"conjecture": "^0.1.2",
2828
"egad": "^0.2.0",
2929
"inquirer": "^7.0.0",
30+
"jsesc": "^2.5.2",
3031
"lodash.camelcase": "^4.3.0",
3132
"lodash.kebabcase": "^4.1.1",
3233
"stringify-author": "^0.1.3",

0 commit comments

Comments
 (0)