Skip to content

Commit

Permalink
improve regex to only remove wrapping single and double quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
meirish committed May 21, 2019
1 parent e11fb01 commit b02978d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ui/app/lib/console-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 !== '')
Expand Down
24 changes: 24 additions & 0 deletions ui/tests/unit/lib/console-helpers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down

0 comments on commit b02978d

Please sign in to comment.