From b02978d1ccf9332e3f1c2be424d1cd2d481b32c9 Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Tue, 21 May 2019 11:29:44 -0500 Subject: [PATCH] improve regex to only remove wrapping single and double quotes --- ui/app/lib/console-helpers.js | 4 ++-- ui/tests/unit/lib/console-helpers-test.js | 24 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ui/app/lib/console-helpers.js b/ui/app/lib/console-helpers.js index eae59a2dfb4d..f68e49462715 100644 --- a/ui/app/lib/console-helpers.js +++ b/ui/app/lib/console-helpers.js @@ -74,8 +74,8 @@ export function parseCommand(command, shouldThrow) { let strippedArg = arg // we'll have arg=something or arg="lol I need spaces", so need to split on the first = .split(/=(.+)/) - // remove " at the beginning and end of each item - .map(item => item.replace(/^"|"$/gi, '')) + // remove matched wrapping " or ' from each item + .map(item => item.replace(/^("|')(.+)(\1)$/, '$2')) // if there were quotes, there's an empty string as the last member in the array that we don't want, // so filter it out .filter(str => str !== '') diff --git a/ui/tests/unit/lib/console-helpers-test.js b/ui/tests/unit/lib/console-helpers-test.js index 3ba448fd2585..d3c7fafd1c4c 100644 --- a/ui/tests/unit/lib/console-helpers-test.js +++ b/ui/tests/unit/lib/console-helpers-test.js @@ -53,6 +53,30 @@ module('Unit | Lib | console helpers', function() { ], ], }, + { + name: 'write with double quotes', + command: `vault write \ + auth/token/create \ + policies="foo" + `, + expected: ['write', [], 'auth/token/create', ['policies=foo']], + }, + { + name: 'write with single quotes', + command: `vault write \ + auth/token/create \ + policies='foo' + `, + expected: ['write', [], 'auth/token/create', ['policies=foo']], + }, + { + name: 'write with unmatched quotes', + command: `vault write \ + auth/token/create \ + policies='foo + `, + expected: ['write', [], 'auth/token/create', ["policies='foo"]], + }, { name: 'read with field', command: `vault read -field=access_key aws/creds/my-role`,