mirror of https://github.com/hashicorp/consul
The Consul API can pass through `Value: null` which does not get cast to a string by ember-data. This snowballs into problems with `atob` which then tried to decode `null`. There are 2 problems here. 1. `Value` should never be `null` - I've added a removeNull function to shallowly loop though props and remove properties that are `null`, for the moment this is only on single KV JSON responses - therefore `Value` will never be `null` which is the root of the problem 2. `atob` doesn't quite follow the `window.atob` API in that the `window.atob` API casts everything down to a string first, therefore it will try to decode `null` > `'null'` > `crazy unicode thing`. - I've commented in a fix for this, but whilst this shouldn't be causing anymore problems in our UI (now that `Value` is never `null`), I'll uncomment it in another future release. Tests are already written for it which more closely follow `window.atob` but skipped for now (next commit)pull/4343/head
parent
6a407a044e
commit
b29546e578
@ -0,0 +1,9 @@
|
||||
export default function(obj) {
|
||||
// non-recursive for the moment
|
||||
return Object.keys(obj).reduce(function(prev, item, i, arr) {
|
||||
if (obj[item] !== null) {
|
||||
return { ...prev, ...{ [item]: obj[item] } };
|
||||
}
|
||||
return prev;
|
||||
}, {});
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
import removeNull from 'consul-ui/utils/remove-null';
|
||||
import { skip } from 'qunit';
|
||||
import { module, test } from 'qunit';
|
||||
|
||||
module('Unit | Utility | remove null');
|
||||
|
||||
test('it removes null valued properties shallowly', function(assert) {
|
||||
[
|
||||
{
|
||||
test: {
|
||||
Value: null,
|
||||
},
|
||||
expected: {},
|
||||
},
|
||||
{
|
||||
test: {
|
||||
Key: 'keyname',
|
||||
Value: null,
|
||||
},
|
||||
expected: {
|
||||
Key: 'keyname',
|
||||
},
|
||||
},
|
||||
{
|
||||
test: {
|
||||
Key: 'keyname',
|
||||
Value: '',
|
||||
},
|
||||
expected: {
|
||||
Key: 'keyname',
|
||||
Value: '',
|
||||
},
|
||||
},
|
||||
{
|
||||
test: {
|
||||
Key: 'keyname',
|
||||
Value: false,
|
||||
},
|
||||
expected: {
|
||||
Key: 'keyname',
|
||||
Value: false,
|
||||
},
|
||||
},
|
||||
].forEach(function(item) {
|
||||
const actual = removeNull(item.test);
|
||||
assert.deepEqual(actual, item.expected);
|
||||
});
|
||||
});
|
||||
skip('it removes null valued properties deeply');
|
Loading…
Reference in new issue