From 6a1ce65166829a75fb9a90e8d6f5e30eadfc92a4 Mon Sep 17 00:00:00 2001 From: Arial7 Date: Wed, 8 Mar 2017 11:48:30 +0100 Subject: [PATCH 1/4] Escape double quotes in string prompts --- lib/ask.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ask.js b/lib/ask.js index f2c3c9ef60..bfe50418e2 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] } From f66bc1f4a229e301e6edc280e108e56718ad6d30 Mon Sep 17 00:00:00 2001 From: Arial7 Date: Wed, 8 Mar 2017 11:53:22 +0100 Subject: [PATCH 2/4] Fix code style of lib/ask.js --- lib/ask.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ask.js b/lib/ask.js index bfe50418e2..88650b8aac 100644 --- a/lib/ask.js +++ b/lib/ask.js @@ -57,7 +57,7 @@ function prompt (data, key, prompt, done) { answers[key].forEach(function (multiChoiceAnswer) { data[key][multiChoiceAnswer] = true }) - } else if (typeof answers[key] == "string"){ + } else if (typeof answers[key] === 'string') { data[key] = answers[key].replace(/"/g, '\\"') } else { data[key] = answers[key] From 4d6bab2e8c24dea35cc0b2f6766963a00a87dcb3 Mon Sep 17 00:00:00 2001 From: Arial7 Date: Thu, 9 Mar 2017 12:18:12 +0100 Subject: [PATCH 3/4] Add test for escaping in package.json --- test/e2e/test.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/e2e/test.js b/test/e2e/test.js index e59a5918cd..adc1b6bae8 100644 --- a/test/e2e/test.js +++ b/test/e2e/test.js @@ -34,6 +34,22 @@ function monkeyPatchInquirer (answers) { } describe('vue-cli', () => { + /* eslint-disable quotes */ + const escapedAuthor = "John \"The Tester\" Doe " + + 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 +122,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(escapedAuthor) + 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` From 5ba03d276406a0157baa6a8b66beda848d95b0e6 Mon Sep 17 00:00:00 2001 From: Arial7 Date: Thu, 9 Mar 2017 12:24:38 +0100 Subject: [PATCH 4/4] Remove unneeded var --- test/e2e/test.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/e2e/test.js b/test/e2e/test.js index adc1b6bae8..4cef9c6f0d 100644 --- a/test/e2e/test.js +++ b/test/e2e/test.js @@ -34,9 +34,6 @@ function monkeyPatchInquirer (answers) { } describe('vue-cli', () => { - /* eslint-disable quotes */ - const escapedAuthor = "John \"The Tester\" Doe " - const escapedAnswers = { name: 'vue-cli-test', author: 'John "The Tester" Doe ', @@ -130,7 +127,7 @@ describe('vue-cli', () => { const pkg = fs.readFileSync(`${MOCK_TEMPLATE_BUILD_PATH}/package.json`, 'utf8') try { var validData = JSON.parse(pkg) - expect(validData.author).to.equal(escapedAuthor) + expect(validData.author).to.equal(escapedAnswers.author) done() } catch (err) { done(err)