Skip to content

Commit

Permalink
Merge pull request #388 from Arial7/master
Browse files Browse the repository at this point in the history
Escape double quotes in string prompts
  • Loading branch information
posva authored Mar 20, 2017
2 parents 439aece + 5ba03d2 commit 182feab
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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 @@ -35,6 +35,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 @@ -107,6 +120,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

0 comments on commit 182feab

Please sign in to comment.