UI fix KVv2 in json editor when value is null (#27094)

* fix issue for null value

* add changelog

* add test coverage

* Update advanced-secret.js

* flatten method by moving else if above instead of nested

* changes

* Delete changelog/278094.txt

* add correct changelog

* clean up

* fix
This commit is contained in:
Angel Garbarino 2024-05-17 10:46:24 -06:00 committed by GitHub
parent fea81ab8bc
commit 0554cdaa71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 42 additions and 1 deletions

3
changelog/27094.txt Normal file
View file

@ -0,0 +1,3 @@
```release-note:bug
ui: Fix KVv2 json editor to allow null values.
```

View file

@ -30,6 +30,11 @@ export function obfuscateData(obj) {
for (const key of Object.keys(obj)) {
if (Array.isArray(obj[key])) {
newObj[key] = obj[key].map(() => '********');
} else if (obj[key] === null) {
// unfortunately in javascript typeof null returns object
// this is due to a "historical js bug that will never be fixed"
// we handle this situation here
newObj[key] = '********';
} else if (typeof obj[key] === 'object') {
newObj[key] = obfuscateData(obj[key]);
} else {

View file

@ -108,7 +108,40 @@ module('Unit | Utility | advanced-secret', function () {
},
].forEach((test) => {
const result = obfuscateData(test.data);
assert.deepEqual(result, test.obscured, `obfuscates values of ${test.name}`);
assert.deepEqual(result, test.obscured, `obfuscates object values of ${test.name}`);
});
});
test('it obfuscates null values', function (assert) {
assert.expect(2);
[
{
name: 'null value',
data: {
one: 'fish',
two: 'fish',
three: 'fish',
blue: null,
},
obscured: {
blue: '********',
one: '********',
three: '********',
two: '********',
},
},
{
name: 'null value nested-object',
data: {
one: { two: null },
},
obscured: {
one: { two: '********' },
},
},
].forEach((test) => {
const result = obfuscateData(test.data);
assert.deepEqual(result, test.obscured, `obfuscates null values of ${test.name}`);
});
});