From a0195a506ca54b9a3f2e5bda741a63002b77b565 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 17 Mar 2023 18:46:01 -0400 Subject: [PATCH] Use new configuration format in tests See https://github.com/WICG/sanitizer-api/issues/181 --- tests/cases/std-sanitize.json | 392 ++++++++++++++++++++-------------- tests/parsetests | 17 -- 2 files changed, 226 insertions(+), 183 deletions(-) diff --git a/tests/cases/std-sanitize.json b/tests/cases/std-sanitize.json index a0d4070..c083491 100644 --- a/tests/cases/std-sanitize.json +++ b/tests/cases/std-sanitize.json @@ -354,11 +354,14 @@ }, { "config": { - "dropAttributes": { - "style": [ - "p" - ] - } + "dropAttributes": [ + { + "name": "style", + "elements": [ + "p" + ] + } + ] }, "input": [ "

Click.

div
" @@ -369,7 +372,7 @@ }, { "config": { - "dropAttributes": {} + "dropAttributes": [] }, "input": [ "

Click.

" @@ -380,11 +383,12 @@ }, { "config": { - "dropAttributes": { - "id": [ - "*" - ] - } + "dropAttributes": [ + { + "name": "id", + "elements": "*" + } + ] }, "input": [ "

Click.

" @@ -395,11 +399,12 @@ }, { "config": { - "dropAttributes": { - "data-attribute-with-dashes": [ - "*" - ] - } + "dropAttributes": [ + { + "name": "data-attribute-with-dashes", + "elements": "*" + } + ] }, "input": [ "

Click.

" @@ -410,11 +415,14 @@ }, { "config": { - "allowAttributes": { - "id": [ - "div" - ] - } + "allowAttributes": [ + { + "name": "id", + "elements": [ + "div" + ] + } + ] }, "input": [ "

P

DIV
" @@ -425,11 +433,12 @@ }, { "config": { - "allowAttributes": { - "id": [ - "*" - ] - } + "allowAttributes": [ + { + "name": "id", + "elements": "*" + } + ] }, "input": [ "

Click.

" @@ -440,16 +449,18 @@ }, { "config": { - "dropAttributes": { - "style": [ - "*" - ] - }, - "allowAttributes": { - "style": [ - "*" - ] - } + "dropAttributes": [ + { + "name": "style", + "elements": "*" + } + ], + "allowAttributes": [ + { + "name": "style", + "elements": "*" + } + ] }, "input": [ "

Click.

" @@ -749,11 +760,12 @@ }, { "config": { - "dropAttributes": { - "ID": [ - "*" - ] - } + "dropAttributes": [ + { + "name": "ID", + "elements": "*" + } + ] }, "input": [ "

Click.

" @@ -764,11 +776,12 @@ }, { "config": { - "dropAttributes": { - "ID": [ - "*" - ] - } + "dropAttributes": [ + { + "name": "ID", + "elements": "*" + } + ] }, "input": [ "

Click.

" @@ -779,11 +792,12 @@ }, { "config": { - "dropAttributes": { - "id": [ - "*" - ] - } + "dropAttributes": [ + { + "name": "id", + "elements": "*" + } + ] }, "input": [ "

Click.

" @@ -889,14 +903,18 @@ }, { "config": { - "allowAttributes": { - "hello": [ - "*" - ], - "world": [ - "b" - ] - } + "allowAttributes": [ + { + "name": "hello", + "elements": "*" + }, + { + "name": "world", + "elements": [ + "b" + ] + } + ] }, "input": [ "
" @@ -907,14 +925,18 @@ }, { "config": { - "allowAttributes": { - "hello": [ - "*" - ], - "world": [ - "b" - ] - }, + "allowAttributes": [ + { + "name": "hello", + "elements": "*" + }, + { + "name": "world", + "elements": [ + "b" + ] + } + ], "allowUnknownMarkup": true }, "input": [ @@ -926,14 +948,18 @@ }, { "config": { - "dropAttributes": { - "hello": [ - "*" - ], - "world": [ - "b" - ] - } + "dropAttributes": [ + { + "name": "hello", + "elements": "*" + }, + { + "name": "world", + "elements": [ + "b" + ] + } + ] }, "input": [ "
" @@ -944,14 +970,18 @@ }, { "config": { - "dropAttributes": { - "hello": [ - "*" - ], - "world": [ - "b" - ] - }, + "dropAttributes": [ + { + "name": "hello", + "elements": "*" + }, + { + "name": "world", + "elements": [ + "b" + ] + } + ], "allowUnknownMarkup": true }, "input": [ @@ -1219,11 +1249,14 @@ }, { "config": { - "dropAttributes": { - "style": [ - "p" - ] - } + "dropAttributes": [ + { + "name": "style", + "elements": [ + "p" + ] + } + ] }, "input": "

Click.

div
", "inputType": "template-content", @@ -1232,7 +1265,7 @@ }, { "config": { - "dropAttributes": {} + "dropAttributes": [] }, "input": "

Click.

", "inputType": "template-content", @@ -1241,11 +1274,12 @@ }, { "config": { - "dropAttributes": { - "id": [ - "*" - ] - } + "dropAttributes": [ + { + "name": "id", + "elements": "*" + } + ] }, "input": "

Click.

", "inputType": "template-content", @@ -1254,11 +1288,12 @@ }, { "config": { - "dropAttributes": { - "data-attribute-with-dashes": [ - "*" - ] - } + "dropAttributes": [ + { + "name": "data-attribute-with-dashes", + "elements": "*" + } + ] }, "input": "

Click.

", "inputType": "template-content", @@ -1267,11 +1302,14 @@ }, { "config": { - "allowAttributes": { - "id": [ - "div" - ] - } + "allowAttributes": [ + { + "name": "id", + "elements": [ + "div" + ] + } + ] }, "input": "

P

DIV
", "inputType": "template-content", @@ -1280,11 +1318,12 @@ }, { "config": { - "allowAttributes": { - "id": [ - "*" - ] - } + "allowAttributes": [ + { + "name": "id", + "elements": "*" + } + ] }, "input": "

Click.

", "inputType": "template-content", @@ -1293,16 +1332,18 @@ }, { "config": { - "dropAttributes": { - "style": [ - "*" - ] - }, - "allowAttributes": { - "style": [ - "*" - ] - } + "dropAttributes": [ + { + "name": "style", + "elements": "*" + } + ], + "allowAttributes": [ + { + "name": "style", + "elements": "*" + } + ] }, "input": "

Click.

", "inputType": "template-content", @@ -1544,11 +1585,12 @@ }, { "config": { - "dropAttributes": { - "ID": [ - "*" - ] - } + "dropAttributes": [ + { + "name": "ID", + "elements": "*" + } + ] }, "input": "

Click.

", "inputType": "template-content", @@ -1557,11 +1599,12 @@ }, { "config": { - "dropAttributes": { - "ID": [ - "*" - ] - } + "dropAttributes": [ + { + "name": "ID", + "elements": "*" + } + ] }, "input": "

Click.

", "inputType": "template-content", @@ -1570,11 +1613,12 @@ }, { "config": { - "dropAttributes": { - "id": [ - "*" - ] - } + "dropAttributes": [ + { + "name": "id", + "elements": "*" + } + ] }, "input": "

Click.

", "inputType": "template-content", @@ -1666,14 +1710,18 @@ }, { "config": { - "allowAttributes": { - "hello": [ - "*" - ], - "world": [ - "b" - ] - } + "allowAttributes": [ + { + "name": "hello", + "elements": "*" + }, + { + "name": "world", + "elements": [ + "b" + ] + } + ] }, "input": "
", "inputType": "template-content", @@ -1682,14 +1730,18 @@ }, { "config": { - "allowAttributes": { - "hello": [ - "*" - ], - "world": [ - "b" - ] - }, + "allowAttributes": [ + { + "name": "hello", + "elements": "*" + }, + { + "name": "world", + "elements": [ + "b" + ] + } + ], "allowUnknownMarkup": true }, "input": "
", @@ -1699,14 +1751,18 @@ }, { "config": { - "dropAttributes": { - "hello": [ - "*" - ], - "world": [ - "b" - ] - } + "dropAttributes": [ + { + "name": "hello", + "elements": "*" + }, + { + "name": "world", + "elements": [ + "b" + ] + } + ] }, "input": "
", "inputType": "template-content", @@ -1715,14 +1771,18 @@ }, { "config": { - "dropAttributes": { - "hello": [ - "*" - ], - "world": [ - "b" - ] - }, + "dropAttributes": [ + { + "name": "hello", + "elements": "*" + }, + { + "name": "world", + "elements": [ + "b" + ] + } + ], "allowUnknownMarkup": true }, "input": "
", diff --git a/tests/parsetests b/tests/parsetests index a90bb6a..7e9f3f6 100755 --- a/tests/parsetests +++ b/tests/parsetests @@ -84,23 +84,6 @@ window.test = function(prog, message) { window.genericTestSet.push(window.genericTest); }; window.Sanitizer = function(conf) { - if (conf) { - if (Array.isArray(conf.dropAttributes)) { - var o = {}; - conf.dropAttributes.forEach(function(v) { - - o[v.name] = (v.elements === "*") ? ["*"] : v.elements; - }); - conf.dropAttributes = o; - } - if (Array.isArray(conf.allowAttributes)) { - var o = {}; - conf.allowAttributes.forEach(function(v) { - o[v.name] = (v.elements === "*") ? ["*"] : v.elements; - }); - conf.allowAttributes = o; - } - } window.genericTest.config = conf || null; return { sanitize: function(dom) {