mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-20 20:00:33 +03:00
fix(plugin-helper): avoid some malformed attributes in attrsToString (#26)
* attrsToString: To avoid some malformed attributes
Error:
```
TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at attrsToString
```
This errors appears if no `attrs` setted in custom tag:
```
const BBcodePresetTemp = BbobPresetHTML5.extend((tags: any) => {
tags.br = () => ({
tag: 'br',
// attrs: {}, // <-- Comment this line for error and add [br] to text
content: null,
});
return tags;
});
```
This commit is contained in:
committed by
Nikolay Kostyurin
parent
5291543855
commit
09ff9af9a2
@@ -52,10 +52,16 @@ const attrValue = (name, value) => {
|
|||||||
* Transforms attrs to html params string
|
* Transforms attrs to html params string
|
||||||
* @param values
|
* @param values
|
||||||
*/
|
*/
|
||||||
const attrsToString = values =>
|
const attrsToString = (values) => {
|
||||||
Object.keys(values)
|
// To avoid some malformed attributes
|
||||||
|
if (typeof values === 'undefined') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return Object.keys(values)
|
||||||
.reduce((arr, key) => [...arr, attrValue(key, values[key])], [''])
|
.reduce((arr, key) => [...arr, attrValue(key, values[key])], [''])
|
||||||
.join(' ');
|
.join(' ');
|
||||||
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
attrsToString,
|
attrsToString,
|
||||||
|
|||||||
@@ -79,4 +79,8 @@ describe('@bbob/plugin-helper', () => {
|
|||||||
disabled: true
|
disabled: true
|
||||||
})).toBe(` tag="test" foo="bar" disabled`)
|
})).toBe(` tag="test" foo="bar" disabled`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('attrsToString undefined', () => {
|
||||||
|
expect(attrsToString(undefined)).toBe('')
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user