diff --git a/packages/bbob-plugin-helper/src/index.js b/packages/bbob-plugin-helper/src/index.js index 5da62b8..d9db9aa 100644 --- a/packages/bbob-plugin-helper/src/index.js +++ b/packages/bbob-plugin-helper/src/index.js @@ -52,10 +52,16 @@ const attrValue = (name, value) => { * Transforms attrs to html params string * @param values */ -const attrsToString = values => - Object.keys(values) +const attrsToString = (values) => { + // To avoid some malformed attributes + if (typeof values === 'undefined') { + return ''; + } + + return Object.keys(values) .reduce((arr, key) => [...arr, attrValue(key, values[key])], ['']) .join(' '); +}; export { attrsToString, diff --git a/packages/bbob-plugin-helper/test/index.test.js b/packages/bbob-plugin-helper/test/index.test.js index 4f4fde1..59f2dfd 100644 --- a/packages/bbob-plugin-helper/test/index.test.js +++ b/packages/bbob-plugin-helper/test/index.test.js @@ -79,4 +79,8 @@ describe('@bbob/plugin-helper', () => { disabled: true })).toBe(` tag="test" foo="bar" disabled`) }) + + test('attrsToString undefined', () => { + expect(attrsToString(undefined)).toBe('') + }) });