Browse Source

Use new configuration format in tests

See https://github.com/WICG/sanitizer-api/issues/181
master
J. King 1 year ago
parent
commit
a0195a506c
  1. 392
      tests/cases/std-sanitize.json
  2. 17
      tests/parsetests

392
tests/cases/std-sanitize.json

@ -354,11 +354,14 @@
},
{
"config": {
"dropAttributes": {
"style": [
"p"
]
}
"dropAttributes": [
{
"name": "style",
"elements": [
"p"
]
}
]
},
"input": [
"<!DOCTYPE html><body><p style='color: black'>Click.</p><div style='color: white'>div</div>"
@ -369,7 +372,7 @@
},
{
"config": {
"dropAttributes": {}
"dropAttributes": []
},
"input": [
"<!DOCTYPE html><body><p id='test'>Click.</p>"
@ -380,11 +383,12 @@
},
{
"config": {
"dropAttributes": {
"id": [
"*"
]
}
"dropAttributes": [
{
"name": "id",
"elements": "*"
}
]
},
"input": [
"<!DOCTYPE html><body><p id='test'>Click.</p>"
@ -395,11 +399,12 @@
},
{
"config": {
"dropAttributes": {
"data-attribute-with-dashes": [
"*"
]
}
"dropAttributes": [
{
"name": "data-attribute-with-dashes",
"elements": "*"
}
]
},
"input": [
"<!DOCTYPE html><body><p id='p' data-attribute-with-dashes='123'>Click.</p><script>document.getElementById('p').dataset.attributeWithDashes=123;</script>"
@ -410,11 +415,14 @@
},
{
"config": {
"allowAttributes": {
"id": [
"div"
]
}
"allowAttributes": [
{
"name": "id",
"elements": [
"div"
]
}
]
},
"input": [
"<!DOCTYPE html><body><p id='p'>P</p><div id='div'>DIV</div>"
@ -425,11 +433,12 @@
},
{
"config": {
"allowAttributes": {
"id": [
"*"
]
}
"allowAttributes": [
{
"name": "id",
"elements": "*"
}
]
},
"input": [
"<!DOCTYPE html><body><p id='test' onclick='a= 123'>Click.</p>"
@ -440,16 +449,18 @@
},
{
"config": {
"dropAttributes": {
"style": [
"*"
]
},
"allowAttributes": {
"style": [
"*"
]
}
"dropAttributes": [
{
"name": "style",
"elements": "*"
}
],
"allowAttributes": [
{
"name": "style",
"elements": "*"
}
]
},
"input": [
"<!DOCTYPE html><body><p style='color: black'>Click.</p>"
@ -749,11 +760,12 @@
},
{
"config": {
"dropAttributes": {
"ID": [
"*"
]
}
"dropAttributes": [
{
"name": "ID",
"elements": "*"
}
]
},
"input": [
"<!DOCTYPE html><body><p id=\"test\">Click.</p>"
@ -764,11 +776,12 @@
},
{
"config": {
"dropAttributes": {
"ID": [
"*"
]
}
"dropAttributes": [
{
"name": "ID",
"elements": "*"
}
]
},
"input": [
"<!DOCTYPE html><body><p ID=\"test\">Click.</p>"
@ -779,11 +792,12 @@
},
{
"config": {
"dropAttributes": {
"id": [
"*"
]
}
"dropAttributes": [
{
"name": "id",
"elements": "*"
}
]
},
"input": [
"<!DOCTYPE html><body><p ID=\"test\">Click.</p>"
@ -889,14 +903,18 @@
},
{
"config": {
"allowAttributes": {
"hello": [
"*"
],
"world": [
"b"
]
}
"allowAttributes": [
{
"name": "hello",
"elements": "*"
},
{
"name": "world",
"elements": [
"b"
]
}
]
},
"input": [
"<!DOCTYPE html><body><div hello='1' world='2'><b hello='3' world='4'>"
@ -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": [
"<!DOCTYPE html><body><div hello='1' world='2'><b hello='3' world='4'>"
@ -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": "<p style='color: black'>Click.</p><div style='color: white'>div</div>",
"inputType": "template-content",
@ -1232,7 +1265,7 @@
},
{
"config": {
"dropAttributes": {}
"dropAttributes": []
},
"input": "<p id='test'>Click.</p>",
"inputType": "template-content",
@ -1241,11 +1274,12 @@
},
{
"config": {
"dropAttributes": {
"id": [
"*"
]
}
"dropAttributes": [
{
"name": "id",
"elements": "*"
}
]
},
"input": "<p id='test'>Click.</p>",
"inputType": "template-content",
@ -1254,11 +1288,12 @@
},
{
"config": {
"dropAttributes": {
"data-attribute-with-dashes": [
"*"
]
}
"dropAttributes": [
{
"name": "data-attribute-with-dashes",
"elements": "*"
}
]
},
"input": "<p id='p' data-attribute-with-dashes='123'>Click.</p><script>document.getElementById('p').dataset.attributeWithDashes=123;</script>",
"inputType": "template-content",
@ -1267,11 +1302,14 @@
},
{
"config": {
"allowAttributes": {
"id": [
"div"
]
}
"allowAttributes": [
{
"name": "id",
"elements": [
"div"
]
}
]
},
"input": "<p id='p'>P</p><div id='div'>DIV</div>",
"inputType": "template-content",
@ -1280,11 +1318,12 @@
},
{
"config": {
"allowAttributes": {
"id": [
"*"
]
}
"allowAttributes": [
{
"name": "id",
"elements": "*"
}
]
},
"input": "<p id='test' onclick='a= 123'>Click.</p>",
"inputType": "template-content",
@ -1293,16 +1332,18 @@
},
{
"config": {
"dropAttributes": {
"style": [
"*"
]
},
"allowAttributes": {
"style": [
"*"
]
}
"dropAttributes": [
{
"name": "style",
"elements": "*"
}
],
"allowAttributes": [
{
"name": "style",
"elements": "*"
}
]
},
"input": "<p style='color: black'>Click.</p>",
"inputType": "template-content",
@ -1544,11 +1585,12 @@
},
{
"config": {
"dropAttributes": {
"ID": [
"*"
]
}
"dropAttributes": [
{
"name": "ID",
"elements": "*"
}
]
},
"input": "<p id=\"test\">Click.</p>",
"inputType": "template-content",
@ -1557,11 +1599,12 @@
},
{
"config": {
"dropAttributes": {
"ID": [
"*"
]
}
"dropAttributes": [
{
"name": "ID",
"elements": "*"
}
]
},
"input": "<p ID=\"test\">Click.</p>",
"inputType": "template-content",
@ -1570,11 +1613,12 @@
},
{
"config": {
"dropAttributes": {
"id": [
"*"
]
}
"dropAttributes": [
{
"name": "id",
"elements": "*"
}
]
},
"input": "<p ID=\"test\">Click.</p>",
"inputType": "template-content",
@ -1666,14 +1710,18 @@
},
{
"config": {
"allowAttributes": {
"hello": [
"*"
],
"world": [
"b"
]
}
"allowAttributes": [
{
"name": "hello",
"elements": "*"
},
{
"name": "world",
"elements": [
"b"
]
}
]
},
"input": "<div hello='1' world='2'><b hello='3' world='4'>",
"inputType": "template-content",
@ -1682,14 +1730,18 @@
},
{
"config": {
"allowAttributes": {
"hello": [
"*"
],
"world": [
"b"
]
},
"allowAttributes": [
{
"name": "hello",
"elements": "*"
},
{
"name": "world",
"elements": [
"b"
]
}
],
"allowUnknownMarkup": true
},
"input": "<div hello='1' world='2'><b hello='3' world='4'>",
@ -1699,14 +1751,18 @@
},
{
"config": {
"dropAttributes": {
"hello": [
"*"
],
"world": [
"b"
]
}
"dropAttributes": [
{
"name": "hello",
"elements": "*"
},
{
"name": "world",
"elements": [
"b"
]
}
]
},
"input": "<div hello='1' world='2'><b hello='3' world='4'>",
"inputType": "template-content",
@ -1715,14 +1771,18 @@
},
{
"config": {
"dropAttributes": {
"hello": [
"*"
],
"world": [
"b"
]
},
"dropAttributes": [
{
"name": "hello",
"elements": "*"
},
{
"name": "world",
"elements": [
"b"
]
}
],
"allowUnknownMarkup": true
},
"input": "<div hello='1' world='2'><b hello='3' world='4'>",

17
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) {

Loading…
Cancel
Save