Skip to content

Commit 182feab

Browse files
authored
Merge pull request vuejs#388 from Arial7/master
Escape double quotes in string prompts
2 parents 439aece + 5ba03d2 commit 182feab

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/ask.js

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ function prompt (data, key, prompt, done) {
5757
answers[key].forEach(function (multiChoiceAnswer) {
5858
data[key][multiChoiceAnswer] = true
5959
})
60+
} else if (typeof answers[key] === 'string') {
61+
data[key] = answers[key].replace(/"/g, '\\"')
6062
} else {
6163
data[key] = answers[key]
6264
}

test/e2e/test.js

+29
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ function monkeyPatchInquirer (answers) {
3535
}
3636

3737
describe('vue-cli', () => {
38+
const escapedAnswers = {
39+
name: 'vue-cli-test',
40+
author: 'John "The Tester" Doe <john@doe.com>',
41+
description: 'vue-cli e2e test',
42+
preprocessor: {
43+
less: true,
44+
sass: true
45+
},
46+
pick: 'no',
47+
noEscape: true
48+
49+
}
50+
3851
const answers = {
3952
name: 'vue-cli-test',
4053
author: 'John Doe <john@doe.com>',
@@ -107,6 +120,22 @@ describe('vue-cli', () => {
107120
})
108121
})
109122

123+
it('generate a vaild package.json with escaped author', done => {
124+
monkeyPatchInquirer(escapedAnswers)
125+
generate('test', MOCK_TEMPLATE_REPO_PATH, MOCK_TEMPLATE_BUILD_PATH, err => {
126+
if (err) done(err)
127+
128+
const pkg = fs.readFileSync(`${MOCK_TEMPLATE_BUILD_PATH}/package.json`, 'utf8')
129+
try {
130+
var validData = JSON.parse(pkg)
131+
expect(validData.author).to.equal(escapedAnswers.author)
132+
done()
133+
} catch (err) {
134+
done(err)
135+
}
136+
})
137+
})
138+
110139
it('avoid rendering files that do not have mustaches', done => {
111140
monkeyPatchInquirer(answers)
112141
const binFilePath = `${MOCK_TEMPLATE_REPO_PATH}/template/bin.file`

0 commit comments

Comments
 (0)