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`,