diff --git a/lib/ask.js b/lib/ask.js index f2c3c9ef60..88650b8aac 100644 --- a/lib/ask.js +++ b/lib/ask.js @@ -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] } diff --git a/test/e2e/test.js b/test/e2e/test.js index e59a5918cd..4cef9c6f0d 100644 --- a/test/e2e/test.js +++ b/test/e2e/test.js @@ -34,6 +34,19 @@ function monkeyPatchInquirer (answers) { } describe('vue-cli', () => { + const escapedAnswers = { + name: 'vue-cli-test', + author: 'John "The Tester" Doe ', + description: 'vue-cli e2e test', + preprocessor: { + less: true, + sass: true + }, + pick: 'no', + noEscape: true + + } + const answers = { name: 'vue-cli-test', author: 'John Doe ', @@ -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`