From 767f2cb208c2f37376db08cd554456de186a4440 Mon Sep 17 00:00:00 2001 From: ache Date: Sun, 27 May 2018 11:07:07 +0200 Subject: Add more tests again --- __tests__/index.js | 21 +++++++++++++++++++++ index.js | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/__tests__/index.js b/__tests__/index.js index 239e1aa..199b8e4 100644 --- a/__tests__/index.js +++ b/__tests__/index.js @@ -127,3 +127,24 @@ test('extended-global', t => { t.deepEqual(parse(contents), parse(`

Wait ! You are beautiful !

`)); }); +test('extended-invalid-scope', t => { + const renderExtended = generateExtendParser({scope: 'invalid', extend: {strong: ['exAttr']}}); + const invalidString = `*Wait* ! You are **beautiful**{ exAttr="true" onload="qdss" pss="NOK" } !`; + const {contents} = renderExtended(invalidString); + t.deepEqual(parse(contents), parse(`

Wait ! You are beautiful !

`)); +}); + +test('invalid-scope', t => { + const renderExtended = generateExtendParser({extend: 'exAttr'}); + const invalidString = ` *Wait* ! I **love**{ exAttr="true" onload="qdss" pss="NOK" } you !`; + const {contents} = renderExtended(invalidString); + t.deepEqual(parse(contents), parse(`

Wait ! I love you !

`)); +}); + +test('invalid-extend', t => { + const renderExtended = generateExtendParser({extend: 'exAttr'}); + const invalidString = ` *Wait* ! I **love**{ exAttr="true" onload="qdss" attr="NOK" style="color: red;"} you!`; + const {contents} = renderExtended(invalidString); + t.deepEqual(parse(contents), parse(`

Wait ! I love you!

`)); +}); + diff --git a/index.js b/index.js index dac4412..e49768c 100644 --- a/index.js +++ b/index.js @@ -151,6 +151,7 @@ function filterAttributes(prop, config, type) { } break; case 'extended': + default: 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 @@ -158,7 +159,6 @@ function filterAttributes(prop, config, type) { inScope = orFunc(inScope, isSpecific); // Or if it in the global scope fallthrough case 'global': - default: inScope = orFunc(inScope, isGlobal); if (allowDangerousDOMEventHandlers) { // If allowed add dangerous attributes to global scope inScope = orFunc(inScope, isDangerous); -- cgit v1.2.3