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

Loading…
Cancel
Save