From fd7d2e7cf485902c4662468b744451427066ac60 Mon Sep 17 00:00:00 2001 From: ache Date: Sat, 19 May 2018 10:09:19 +0200 Subject: Add more tests --- index.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index ace52e5..b9eba7e 100644 --- a/index.js +++ b/index.js @@ -39,6 +39,7 @@ const convTypeTag = { emphasis: 'em', delete: 's', inlineCode: 'code', + '*': '*', }; /* TODO : @@ -102,6 +103,14 @@ function filterAttributes(prop, config, type) { const {allowDangerousDOMEventHandlers} = config; const specific = htmlElemAttr; + const extendTag = (extend => { + const t = {}; + Object.getOwnPropertyNames(extend).forEach(p => { + t[convTypeTag[p]] = extend[p]; + }); + return t; + })(extend); + Object.getOwnPropertyNames(prop).forEach(p => { if (p !== 'key' && p !== 'class' && p !== 'id') { prop[p] = prop[p] || ''; @@ -109,7 +118,7 @@ function filterAttributes(prop, config, type) { }); const isDangerous = p => DOMEventHandler.indexOf(p) >= 0; - const isSpecific = p => 'type' in specific && specific[type].indexOf(p) >= 0; + const isSpecific = p => type in specific && specific[type].indexOf(p) >= 0; const isGlobal = p => htmlElemAttr['*'].indexOf(p) >= 0; let inScope = _ => false; @@ -127,8 +136,9 @@ function filterAttributes(prop, config, type) { inScope = x => !isDangerous(x); } break; - case 'extented': - inScope = p => extend[type].indexOf(p) >= 0; + case 'extended': + inScope = p => extendTag && type in extendTag && extendTag[type].indexOf(p) >= 0; + inScope = orFunc(inScope, p => '*' in extendTag && extendTag['*'].indexOf(p) >= 0); // Or if it in the specific scope, fallthrough case 'specific': inScope = orFunc(inScope, isSpecific); @@ -141,10 +151,8 @@ function filterAttributes(prop, config, type) { } } - const filterFunction = x => !inScope(x); - Object.getOwnPropertyNames(prop).forEach(p => { - if (filterFunction(p)) { + if (!inScope(p)) { delete prop[p]; } }); @@ -163,7 +171,7 @@ function remarkAttr(userConfig) { allowDangerousDOMEventHandlers: false, elements: supportedElements, extend: {}, - scope: 'specific', + scope: 'extended', }; const config = {...defaultConfig, ...userConfig}; -- cgit v1.2.3-54-g00ecf