Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ask.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ function prompt (data, key, prompt, done) {
answers[key].forEach(function (multiChoiceAnswer) {
data[key][multiChoiceAnswer] = true
})
} else if (typeof answers[key] === 'string') {
data[key] = answers[key].replace(/"/g, '\\"')
} else {
data[key] = answers[key]
}
Expand Down
29 changes: 29 additions & 0 deletions test/e2e/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ function monkeyPatchInquirer (answers) {
}

describe('vue-cli', () => {
const escapedAnswers = {
name: 'vue-cli-test',
author: 'John "The Tester" Doe <john@doe.com>',
description: 'vue-cli e2e test',
preprocessor: {
less: true,
sass: true
},
pick: 'no',
noEscape: true

}

const answers = {
name: 'vue-cli-test',
author: 'John Doe <john@doe.com>',
Expand Down Expand Up @@ -106,6 +119,22 @@ describe('vue-cli', () => {
})
})

it('generate a vaild package.json with escaped author', done => {
monkeyPatchInquirer(escapedAnswers)
generate('test', MOCK_TEMPLATE_REPO_PATH, MOCK_TEMPLATE_BUILD_PATH, err => {
if (err) done(err)

const pkg = fs.readFileSync(`${MOCK_TEMPLATE_BUILD_PATH}/package.json`, 'utf8')
try {
var validData = JSON.parse(pkg)
expect(validData.author).to.equal(escapedAnswers.author)
done()
} catch (err) {
done(err)
}
})
})

it('avoid rendering files that do not have mustaches', done => {
monkeyPatchInquirer(answers)
const binFilePath = `${MOCK_TEMPLATE_REPO_PATH}/template/bin.file`
Expand Down