Skip to content

Commit bd3f214

Browse files
Merge branch 'master' into feature/export-and-load-automation-scripts
2 parents 85874f7 + e45821e commit bd3f214

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

webviews/src/views/RokuRegistryView/RokuRegistryView.spec.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,45 @@ import { registryView } from './RokuRegistryView';
44
describe('RegistryView', () => {
55
describe('formatValues', () => {
66
it('should convert json into an object with the correct values', () => {
7+
const inputValue = 1;
78
const input = {
8-
a: '{"b": 1}'
9+
a: `{"b": ${inputValue}}`
910
};
1011
const result = registryView.formatValues(input);
11-
expect(result.a.b).to.equal(1);
12+
expect(result.a.b).to.equal(inputValue);
1213
});
1314

1415
it('should correctly handle multiple levels', () => {
16+
const inputValue = 1;
1517
const input = {
1618
a: {
17-
b: '{"c": 1}'
19+
b: `{"c": ${inputValue}}`
1820
}
1921
};
2022
const result = registryView.formatValues(input);
21-
expect(result.a.b.c).to.equal(1);
23+
expect(result.a.b.c).to.equal(inputValue);
2224
});
2325

24-
it('should return the incoming value if not JSON', () => {
26+
it('should not try and convert strings that look like numbers into numbers', () => {
27+
const inputValue = '1';
2528
const input = {
2629
a: {
27-
b: 1
30+
b: inputValue
2831
}
2932
};
3033
const result = registryView.formatValues(input);
31-
expect(result.a.b).to.equal(input.a.b);
34+
expect(result.a.b).to.equal(inputValue);
35+
});
36+
37+
it('should not try and convert strings that look like booleans into booleans', () => {
38+
const inputValue = 'true';
39+
const input = {
40+
a: {
41+
b: inputValue
42+
}
43+
};
44+
const result = registryView.formatValues(input);
45+
expect(result.a.b).to.equal(inputValue);
3246
});
3347
});
3448
});

webviews/src/views/RokuRegistryView/RokuRegistryView.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ class RegistryView {
88
} else if (typeof values[key] === 'string') {
99
try {
1010
// Try and parse it to see if it's json
11-
values[key] = JSON.parse(values[key]);
11+
// Only want to convert with json if not a number or boolean
12+
const result = JSON.parse(values[key]);
13+
if (typeof result !== 'number' && typeof result !== 'boolean') {
14+
values[key] = result;
15+
}
1216
} catch (e) {
1317
// If we fail we leave it unchanged
1418
}

0 commit comments

Comments
 (0)