From 83a88b96c4e9bb2b311e9b8bb956a81392631fd8 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Mon, 24 Jun 2019 16:29:33 +1000 Subject: [PATCH 1/4] attrsToString: To avoid some malformed attributes Error: ``` TypeError: Cannot convert undefined or null to object at Function.keys () 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; }); ``` The dirty fix. Should be test and warning added. --- packages/bbob-plugin-helper/src/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/bbob-plugin-helper/src/index.js b/packages/bbob-plugin-helper/src/index.js index 5da62b88..ab97ed15 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 (!!values) { + return ''; + } + + return Object.keys(values) .reduce((arr, key) => [...arr, attrValue(key, values[key])], ['']) .join(' '); +}; export { attrsToString, From 540667938e22532beaea5ea268833b639274b11e Mon Sep 17 00:00:00 2001 From: Vladimir Date: Mon, 24 Jun 2019 17:15:30 +1000 Subject: [PATCH 2/4] eslint --- packages/bbob-plugin-helper/src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/bbob-plugin-helper/src/index.js b/packages/bbob-plugin-helper/src/index.js index ab97ed15..166dea92 100644 --- a/packages/bbob-plugin-helper/src/index.js +++ b/packages/bbob-plugin-helper/src/index.js @@ -54,8 +54,8 @@ const attrValue = (name, value) => { */ const attrsToString = (values) => { // To avoid some malformed attributes - if (!!values) { - return ''; + if (undefined === values) { + return ''; } return Object.keys(values) From 73ac325d34214af9e21606bc6ed1b258ef2b3b25 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 27 Jun 2019 13:18:02 +1000 Subject: [PATCH 3/4] Update index.js --- packages/bbob-plugin-helper/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bbob-plugin-helper/src/index.js b/packages/bbob-plugin-helper/src/index.js index 166dea92..d9db9aaf 100644 --- a/packages/bbob-plugin-helper/src/index.js +++ b/packages/bbob-plugin-helper/src/index.js @@ -54,7 +54,7 @@ const attrValue = (name, value) => { */ const attrsToString = (values) => { // To avoid some malformed attributes - if (undefined === values) { + if (typeof values === 'undefined') { return ''; } From 4a82a0b5bd2b72f1d603703030633d1aaa09dc5d Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 27 Jun 2019 13:18:33 +1000 Subject: [PATCH 4/4] Update index.test.js --- packages/bbob-plugin-helper/test/index.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/bbob-plugin-helper/test/index.test.js b/packages/bbob-plugin-helper/test/index.test.js index 4f4fde16..59f2dfdc 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('') + }) });