From 482ad0a0942b8216fb1f64acfcd2e81c1622e7b0 Mon Sep 17 00:00:00 2001 From: Chelsea Shaw Date: Thu, 6 Feb 2020 12:37:38 -0600 Subject: [PATCH] [UI] clear policies in cli (#8291) * fix: entity policies cleared from empty string in UI console * add test for new use case of empty value --- ui/app/lib/console-helpers.js | 4 ++-- ui/tests/unit/lib/console-helpers-test.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ui/app/lib/console-helpers.js b/ui/app/lib/console-helpers.js index 12d7e3c529..139fff99e4 100644 --- a/ui/app/lib/console-helpers.js +++ b/ui/app/lib/console-helpers.js @@ -10,7 +10,8 @@ export function extractDataAndFlags(data, flags) { (accumulator, val) => { // will be "key=value" or "-flag=value" or "foo=bar=baz" // split on the first = - let [item, value] = val.split(/=(.+)/); + // default to value of empty string + let [item, value = ''] = val.split(/=(.+)?/); if (item.startsWith('-')) { let flagName = item.replace(/^-/, ''); if (flagName === 'wrap-ttl') { @@ -26,7 +27,6 @@ export function extractDataAndFlags(data, flags) { return accumulator; } accumulator.data[item] = value; - return accumulator; }, { data: {}, flags: {} } diff --git a/ui/tests/unit/lib/console-helpers-test.js b/ui/tests/unit/lib/console-helpers-test.js index b38f6195cd..2ceffd1fd0 100644 --- a/ui/tests/unit/lib/console-helpers-test.js +++ b/ui/tests/unit/lib/console-helpers-test.js @@ -166,6 +166,17 @@ module('Unit | Lib | console helpers', function() { flags: {}, }, }, + { + name: 'data with empty values', + input: [[`foo=`, 'some=thing'], []], + expected: { + data: { + foo: '', + some: 'thing', + }, + flags: {}, + }, + }, ]; testExtractCases.forEach(function(testCase) {