Skip to content

Commit 6e5318f

Browse files
committed
fix: client: modules: config: input: quote
1 parent ec66ba7 commit 6e5318f

2 files changed

Lines changed: 32 additions & 8 deletions

File tree

client/modules/config/input.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import currify from 'currify';
1+
import {encode} from '#common/entity';
22

3-
const isType = currify((type, object, name) => type === typeof object[name]);
4-
const isBool = isType('boolean');
3+
const isBool = (a) => typeof a === 'boolean';
4+
const isString = (a) => typeof a === 'string';
5+
6+
const {keys} = Object;
57

68
export function getElementByName(selector, element) {
79
const str = `[data-name="js-${selector}"]`;
@@ -19,13 +21,19 @@ export const getName = (element) => {
1921

2022
export const convert = (config) => {
2123
const result = config;
22-
const array = Object.keys(config);
23-
24-
const filtered = array.filter(isBool(config));
2524

26-
for (const name of filtered) {
25+
for (const name of keys(config)) {
2726
const item = config[name];
28-
result[name] = setState(item);
27+
28+
if (isBool(item)) {
29+
result[name] = setState(item);
30+
continue;
31+
}
32+
33+
if (isString(item)) {
34+
result[name] = encode(item);
35+
continue;
36+
}
2937
}
3038

3139
return result;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {test} from 'supertape';
2+
import {convert} from './input.js';
3+
4+
test('cloudcmd: client: config: input: convert', (t) => {
5+
const result = convert({
6+
name: 'hello <world>',
7+
});
8+
9+
const expected = {
10+
name: 'hello &lt;world&gt;',
11+
};
12+
13+
t.deepEqual(result, expected);
14+
t.end();
15+
});
16+

0 commit comments

Comments
 (0)