Commit f59b60ba authored by Hitoshi Yoshida's avatar Hitoshi Yoshida Committed by Commit Bot

bindings: Make SanitizerConfig member types non-null

SanitierConfig is a construction options for Sanitizer.
Its members are defined to have non-null types in spec[1], and
this CL makes its Blink implementation to follow the spec.

[1] https://wicg.github.io/sanitizer-api/#sanitizer-api

Bug: 839389, 116418
Change-Id: I86302fe6f36894bf102d23844bb9353ba5bdb1b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2444770Reviewed-by: default avatarYifan Luo <lyf@chromium.org>
Commit-Queue: Hitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814159}
parent bfc6988c
......@@ -28,9 +28,9 @@ Sanitizer* Sanitizer::Create(const SanitizerConfig* config,
Sanitizer::Sanitizer(const SanitizerConfig* config)
: config_(const_cast<SanitizerConfig*>(config)) {
// Format dropElements to uppercases.
if (config->hasDropElementsNonNull()) {
if (config->hasDropElements()) {
Vector<String> l;
for (const String& s : config->dropElementsNonNull()) {
for (const String& s : config->dropElements()) {
l.push_back(s.UpperASCII());
}
config_->setDropElements(l);
......@@ -71,8 +71,7 @@ DocumentFragment* Sanitizer::sanitize(ScriptState* script_state,
fragment->ParseHTML(input, document->QuerySelector("body"));
// Remove all the elements in the dropElements list.
if (config_->hasDropElementsNonNull() ||
config_->hasDropAttributesNonNull()) {
if (config_->hasDropElements() || config_->hasDropAttributes()) {
Node* node = fragment->firstChild();
while (node) {
......@@ -86,8 +85,8 @@ DocumentFragment* Sanitizer::sanitize(ScriptState* script_state,
String node_name = node->nodeName();
// If the current element is dropped, remove current element entirely and
// proceed to its next sibling.
if (config_->hasDropElementsNonNull() &&
config_->dropElementsNonNull().Contains(node_name.UpperASCII())) {
if (config_->hasDropElements() &&
config_->dropElements().Contains(node_name.UpperASCII())) {
Node* tmp = node;
node = NodeTraversal::NextSkippingChildren(*node, fragment);
tmp->remove();
......
......@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://github.com/WICG/sanitizer-api
// https://wicg.github.io/sanitizer-api/#sanitizer-api
dictionary SanitizerConfig {
sequence<DOMString>? dropElements;
sequence<DOMString>? dropAttributes;
sequence<DOMString> dropElements;
sequence<DOMString> dropAttributes;
};
This is a testharness.js-based test.
FAIL SanitizerAPI creator without config. assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI creator with empty config. assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI creator with null as config. assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI creator with undefined as config. assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI creator with config ignore unknown values. assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI config is not editable. assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI creator without config. assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI creator with empty config. assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI creator with null as config. assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI creator with undefined as config. assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI creator with config ignore unknown values. assert_object_equals: expected property "dropElements" missing
PASS SanitizerAPI config is not editable.
PASS SanitizerAPI creator with config {dropElements: []}.
FAIL SanitizerAPI creator with config {dropElements: null}. assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI creator with config {dropElements: undefined}. assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI creator with config {dropElements: null}. Failed to construct 'Sanitizer': The provided value cannot be converted to a sequence.
FAIL SanitizerAPI creator with config {dropElements: undefined}. assert_object_equals: expected property "dropElements" missing
PASS SanitizerAPI creator with config {dropElements: 123}.
PASS SanitizerAPI creator with config {dropElements: div}.
Harness: the test ran to completion.
......
This is a testharness.js-based test.
FAIL SanitizerAPI sanitize function for string assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for html fragment assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for broken html assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for empty object assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for number assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for zeros assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for arithmetic assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for empty string assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for undefined assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for null assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for document assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for html without close tag assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for scripts assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for onclick scripts assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for invalid config_input assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for empty dropElements list assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for test html without close tag with dropElements list ['div'] assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for test script with ["script"] as dropElements list assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for dropElements list ["test", "i"]} assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for dropElements list ["I", "AM"]} assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for dropElements list ["am", "p"]} assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for dropElements list with invalid values} assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitize function for string assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitize function for html fragment assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitize function for broken html assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitize function for empty object assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitize function for number assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitize function for zeros assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitize function for arithmetic assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitize function for empty string assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitize function for undefined assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitize function for null assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitize function for document assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitize function for html without close tag assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitize function for scripts assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitize function for onclick scripts assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitize function for invalid config_input assert_object_equals: expected property "dropElements" missing
PASS SanitizerAPI sanitize function for empty dropElements list
PASS SanitizerAPI sanitize function for test html without close tag with dropElements list ['div']
PASS SanitizerAPI sanitize function for test script with ["script"] as dropElements list
PASS SanitizerAPI sanitize function for dropElements list ["test", "i"]}
PASS SanitizerAPI sanitize function for dropElements list ["I", "AM"]}
PASS SanitizerAPI sanitize function for dropElements list ["am", "p"]}
PASS SanitizerAPI sanitize function for dropElements list with invalid values}
Harness: the test ran to completion.
This is a testharness.js-based test.
FAIL SanitizerAPI sanitizeToString function for string assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for html fragment assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for broken html assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for empty object assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for number assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for zeros assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for arithmetic assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for empty string assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for undefined assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for null assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for document assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for html without close tag assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for scripts assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for onclick scripts assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for invalid config_input assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for empty dropElements list assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for test html without close tag with dropElements list ['div'] assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for test script with ["script"] as dropElements list assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for dropElements list ["test", "i"]} assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for dropElements list ["I", "AM"]} assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for dropElements list ["am", "p"]} assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for dropElements list with invalid values} assert_object_equals: unexpected property "dropAttributes"
FAIL SanitizerAPI sanitizeToString function for string assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitizeToString function for html fragment assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitizeToString function for broken html assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitizeToString function for empty object assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitizeToString function for number assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitizeToString function for zeros assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitizeToString function for arithmetic assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitizeToString function for empty string assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitizeToString function for undefined assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitizeToString function for null assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitizeToString function for document assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitizeToString function for html without close tag assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitizeToString function for scripts assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitizeToString function for onclick scripts assert_object_equals: expected property "dropElements" missing
FAIL SanitizerAPI sanitizeToString function for invalid config_input assert_object_equals: expected property "dropElements" missing
PASS SanitizerAPI sanitizeToString function for empty dropElements list
PASS SanitizerAPI sanitizeToString function for test html without close tag with dropElements list ['div']
PASS SanitizerAPI sanitizeToString function for test script with ["script"] as dropElements list
PASS SanitizerAPI sanitizeToString function for dropElements list ["test", "i"]}
PASS SanitizerAPI sanitizeToString function for dropElements list ["I", "AM"]}
PASS SanitizerAPI sanitizeToString function for dropElements list ["am", "p"]}
PASS SanitizerAPI sanitizeToString function for dropElements list with invalid values}
Harness: the test ran to completion.
......@@ -8,7 +8,7 @@
<body>
<script>
const default_option = {dropElements: null, dropAttributes: null};
const default_option = {};
test(t => {
let s = new Sanitizer();
assert_true(s instanceof Sanitizer);
......@@ -44,32 +44,32 @@
let options = {dropElements: ["div"]};
let s = new Sanitizer(options);
assert_true(s instanceof Sanitizer);
assert_object_equals(s.creationOptions, {dropElements: ["DIV"], dropAttributes: null});
assert_object_equals(s.creationOptions, {dropElements: ["DIV"]});
options.dropElements.push("test");
assert_object_equals(s.creationOptions, {dropElements: ["DIV"], dropAttributes: null});
assert_object_equals(s.creationOptions, {dropElements: ["DIV"]});
s.creationOptions = {dropElements: ["test", "t"]};
assert_object_equals(s.creationOptions, {dropElements: ["DIV"], dropAttributes: null});
assert_object_equals(s.creationOptions, {dropElements: ["DIV"]});
s.creationOptions['dropElements'] = [1,2,3];
assert_object_equals(s.creationOptions, {dropElements: ["DIV"], dropAttributes: null});
assert_object_equals(s.creationOptions, {dropElements: ["DIV"]});
}, "SanitizerAPI config dropElements is not editable.");
test(t => {
let options = {dropAttributes: ["onclick"]};
let s = new Sanitizer(options);
assert_true(s instanceof Sanitizer);
assert_object_equals(s.creationOptions, {dropElements: null, dropAttributes: ["onclick"]});
assert_object_equals(s.creationOptions, {dropAttributes: ["onclick"]});
options.dropAttributes.push("test");
assert_object_equals(s.creationOptions, {dropElements: null, dropAttributes: ["onclick"]});
assert_object_equals(s.creationOptions, {dropAttributes: ["onclick"]});
s.creationOptions = {dropAttributes: ["test", "t"]};
assert_object_equals(s.creationOptions, {dropElements: null, dropAttributes: ["onclick"]});
assert_object_equals(s.creationOptions, {dropAttributes: ["onclick"]});
s.creationOptions['dropAttributes'] = [1,2,3];
assert_object_equals(s.creationOptions, {dropElements: null, dropAttributes: ["onclick"]});
assert_object_equals(s.creationOptions, {dropAttributes: ["onclick"]});
}, "SanitizerAPI config dropAttributes is not editable.");
test(t => {
......@@ -78,13 +78,6 @@
assert_equals(s.sanitizeToString("<div>balabala<i>test</i></div>"), "<div>balabala<i>test</i></div>");
}, "SanitizerAPI creator with config {dropElements: []}.")
test(t => {
let s = new Sanitizer({dropElements: null});
assert_true(s instanceof Sanitizer);
assert_true(s.creationOptions instanceof Object);
assert_object_equals(s.creationOptions, default_option);
}, "SanitizerAPI creator with config {dropElements: null}.")
test(t => {
let s = new Sanitizer({dropElements: undefined});
assert_true(s instanceof Sanitizer);
......@@ -100,6 +93,9 @@
assert_throws_js(TypeError, _ => {let s = new Sanitizer({dropElements: "div"})});
}, "SanitizerAPI creator with config {dropElements: div}.");
test(t => {
assert_throws_js(TypeError, _ => {let s = new Sanitizer({dropElements: null})});
}, "SanitizerAPI creator with config {dropElements: null}.")
test(t => {
let s = new Sanitizer({dropAttributes: []});
......@@ -107,13 +103,6 @@
assert_equals(s.sanitizeToString("<div>balabala<i>test</i></div>"), "<div>balabala<i>test</i></div>");
}, "SanitizerAPI creator with config {dropAttributes: []}.")
test(t => {
let s = new Sanitizer({dropAttributes: null});
assert_true(s instanceof Sanitizer);
assert_true(s.creationOptions instanceof Object);
assert_object_equals(s.creationOptions, default_option);
}, "SanitizerAPI creator with config {dropAttributes: null}.")
test(t => {
let s = new Sanitizer({dropAttributes: undefined});
assert_true(s instanceof Sanitizer);
......@@ -129,6 +118,10 @@
assert_throws_js(TypeError, _ => {let s = new Sanitizer({dropAttributes: "div"})});
}, "SanitizerAPI creator with config {dropAttributes: div}.");
test(t => {
assert_throws_js(TypeError, _ => {let s = new Sanitizer({dropAttributes: null})});
}, "SanitizerAPI creator with config {dropAttributes: null}.")
</script>
</body>
</html>
......@@ -16,7 +16,7 @@
test(t => {
let s = new Sanitizer({});
assert_object_equals(s.creationOptions, {dropElements: null, dropAttributes: null});
assert_object_equals(s.creationOptions, {});
assert_throws_js(TypeError, _ => s.sanitize());
}, "SanitizerAPI sanitize function without argument should throw an error.");
......
......@@ -10,7 +10,7 @@
<script>
test(t => {
let s = new Sanitizer({});
assert_object_equals(s.creationOptions, {dropElements: null, dropAttributes: null});
assert_object_equals(s.creationOptions, {});
assert_throws_js(TypeError, _ => s.sanitizeToString());
}, "SanitizerAPI sanitize function without argument should throw an error.");
......
const testcases = [
{config_input: {}, config_value: {dropElements: null, dropAttributes: null}, value: "test", result: "test", message: "string"},
{config_input: {}, config_value: {dropElements: null, dropAttributes: null}, value: "<b>bla</b>", result: "<b>bla</b>", message: "html fragment"},
{config_input: {}, config_value: {dropElements: null, dropAttributes: null}, value: "<a<embla", result: "", message: "broken html"},
{config_input: {}, config_value: {dropElements: null, dropAttributes: null}, value: {}, result: "[object Object]", message: "empty object"},
{config_input: {}, config_value: {dropElements: null, dropAttributes: null}, value: 1, result: "1", message: "number"},
{config_input: {}, config_value: {dropElements: null, dropAttributes: null}, value: 000, result: "0", message: "zeros"},
{config_input: {}, config_value: {dropElements: null, dropAttributes: null}, value: 1+2, result: "3", message: "arithmetic"},
{config_input: {}, config_value: {dropElements: null, dropAttributes: null}, value: "", result: "", message: "empty string"},
{config_input: {}, config_value: {dropElements: null, dropAttributes: null}, value: undefined, result: "undefined", message: "undefined"},
{config_input: {}, config_value: {dropElements: null, dropAttributes: null}, value: null, result: "null", message: "null"},
{config_input: {}, config_value: {dropElements: null, dropAttributes: null}, value: "<html><head></head><body>test</body></html>", result: "test", message: "document"},
{config_input: {}, config_value: {dropElements: null, dropAttributes: null}, value: "<div>test", result: "<div>test</div>", message: "html without close tag"},
{config_input: {}, config_value: {dropElements: null, dropAttributes: null}, value: "<script>alert('i am a test')<\/script>", result: "", message: "scripts for default configs"},
{config_input: {test: 123}, config_value: {dropElements: null, dropAttributes: null}, value: "test", result: "test", message: "invalid config_input"},
{config_input: {dropElements: []}, config_value: {dropElements:[], dropAttributes: null}, value: "test", result: "test", message: "empty dropElements list"},
{config_input: {dropElements: ["div"]}, config_value: {dropElements:["DIV"], dropAttributes: null}, value: "<div>test</div><c>bla", result: "<c>bla</c>", message: "test html without close tag with dropElements list ['div']"},
{config_input: {dropElements: ["script"]}, config_value: {dropElements:["SCRIPT"], dropAttributes: null}, value: "<script>alert('i am a test')<\/script>", result: "", message: "test script with [\"script\"] as dropElements list"},
{config_input: {dropElements: ["test", "i"]}, config_value: {dropElements:["TEST","I"], dropAttributes: null}, value: "<div>balabala<i>test</i></div><test>t</test>", result: "<div>balabala</div>", message: "dropElements list [\"test\", \"i\"]}"},
{config_input: {dropElements: ["I", "AM"]}, config_value: {dropElements:["I", "AM"], dropAttributes: null}, value: "<div>balabala<am>test</am></div>", result: "<div>balabala</div>", message: "dropElements list [\"I\", \"AM\"]}"},
{config_input: {dropElements: ["am", "p"]}, config_value: {dropElements:["AM","P"], dropAttributes: null}, value: "<div>balabala<i>i</i><p>t</p><test>a</test></div>", result: "<div>balabala<i>i</i><test>a</test></div>", message: "dropElements list [\"am\", \"p\"]}"},
{config_input: {dropElements: [123, [], "test", "i"]}, config_value: {dropElements:["123","","TEST","I"], dropAttributes: null}, value: "<div>balabala<i>test</i></div><test>t</test>", result: "<div>balabala</div>", message: "dropElements list with invalid values}"},
{config_input: {dropAttributes: ["onclick"]}, config_value: {dropElements: null, dropAttributes: ["onclick"]}, value: "<p onclick='a= 123'>Click.</p>", result: "<p>Click.</p>", message: "dropAttributes list [\"onclick\"] with onclick scripts"},
{config_input: {dropAttributes: []}, config_value: {dropElements: null, dropAttributes: []}, value: "<p onclick='a= 123'>Click.</p>", result: "<p onclick=\"a= 123\">Click.</p>", message: "empty dropAttributes list with onclick scripts"},
{config_input: {dropAttributes: ["id"]}, config_value: {dropElements: null, dropAttributes: ["id"]}, value: "<p onclick='a= 123'>Click.</p>", result: "<p onclick=\"a= 123\">Click.</p>", message: "dropAttributes list [\"id\"] with onclick scripts"},
{config_input: {dropAttributes: ["ONCLICK"]}, config_value: {dropElements: null, dropAttributes: ["onclick"]}, value: "<p onclick='a= 123'>Click.</p>", result: "<p>Click.</p>", message: "dropAttributes list [\"ONCLICK\"] with onclick scripts"},
{config_input: {dropAttributes: ["data-attribute-with-dashes"]}, config_value: {dropElements: null, dropAttributes: ["data-attribute-with-dashes"]}, value: "<p id='p' data-attribute-with-dashes='123'>Click.</p><script>document.getElementById('p').dataset.attributeWithDashes=123;</script>", result: "<p id=\"p\">Click.</p><script></script>", message: "dropAttributes list [\"data-attribute-with-dashes\"] with dom dataset js access."},
{config_input: {}, config_value: {}, value: "test", result: "test", message: "string"},
{config_input: {}, config_value: {}, value: "<b>bla</b>", result: "<b>bla</b>", message: "html fragment"},
{config_input: {}, config_value: {}, value: "<a<embla", result: "", message: "broken html"},
{config_input: {}, config_value: {}, value: {}, result: "[object Object]", message: "empty object"},
{config_input: {}, config_value: {}, value: 1, result: "1", message: "number"},
{config_input: {}, config_value: {}, value: 000, result: "0", message: "zeros"},
{config_input: {}, config_value: {}, value: 1+2, result: "3", message: "arithmetic"},
{config_input: {}, config_value: {}, value: "", result: "", message: "empty string"},
{config_input: {}, config_value: {}, value: undefined, result: "undefined", message: "undefined"},
{config_input: {}, config_value: {}, value: null, result: "null", message: "null"},
{config_input: {}, config_value: {}, value: "<html><head></head><body>test</body></html>", result: "test", message: "document"},
{config_input: {}, config_value: {}, value: "<div>test", result: "<div>test</div>", message: "html without close tag"},
{config_input: {}, config_value: {}, value: "<script>alert('i am a test')<\/script>", result: "", message: "scripts for default configs"},
{config_input: {test: 123}, config_value: {}, value: "test", result: "test", message: "invalid config_input"},
{config_input: {dropElements: []}, config_value: {dropElements:[]}, value: "test", result: "test", message: "empty dropElements list"},
{config_input: {dropElements: ["div"]}, config_value: {dropElements:["DIV"]}, value: "<div>test</div><c>bla", result: "<c>bla</c>", message: "test html without close tag with dropElements list ['div']"},
{config_input: {dropElements: ["script"]}, config_value: {dropElements:["SCRIPT"]}, value: "<script>alert('i am a test')<\/script>", result: "", message: "test script with [\"script\"] as dropElements list"},
{config_input: {dropElements: ["test", "i"]}, config_value: {dropElements:["TEST","I"]}, value: "<div>balabala<i>test</i></div><test>t</test>", result: "<div>balabala</div>", message: "dropElements list [\"test\", \"i\"]}"},
{config_input: {dropElements: ["I", "AM"]}, config_value: {dropElements:["I", "AM"]}, value: "<div>balabala<am>test</am></div>", result: "<div>balabala</div>", message: "dropElements list [\"I\", \"AM\"]}"},
{config_input: {dropElements: ["am", "p"]}, config_value: {dropElements:["AM","P"]}, value: "<div>balabala<i>i</i><p>t</p><test>a</test></div>", result: "<div>balabala<i>i</i><test>a</test></div>", message: "dropElements list [\"am\", \"p\"]}"},
{config_input: {dropElements: [123, [], "test", "i"]}, config_value: {dropElements:["123","","TEST","I"]}, value: "<div>balabala<i>test</i></div><test>t</test>", result: "<div>balabala</div>", message: "dropElements list with invalid values}"},
{config_input: {dropAttributes: ["onclick"]}, config_value: {dropAttributes: ["onclick"]}, value: "<p onclick='a= 123'>Click.</p>", result: "<p>Click.</p>", message: "dropAttributes list [\"onclick\"] with onclick scripts"},
{config_input: {dropAttributes: []}, config_value: {dropAttributes: []}, value: "<p onclick='a= 123'>Click.</p>", result: "<p onclick=\"a= 123\">Click.</p>", message: "empty dropAttributes list with onclick scripts"},
{config_input: {dropAttributes: ["id"]}, config_value: {dropAttributes: ["id"]}, value: "<p onclick='a= 123'>Click.</p>", result: "<p onclick=\"a= 123\">Click.</p>", message: "dropAttributes list [\"id\"] with onclick scripts"},
{config_input: {dropAttributes: ["ONCLICK"]}, config_value: {dropAttributes: ["onclick"]}, value: "<p onclick='a= 123'>Click.</p>", result: "<p>Click.</p>", message: "dropAttributes list [\"ONCLICK\"] with onclick scripts"},
{config_input: {dropAttributes: ["data-attribute-with-dashes"]}, config_value: {dropAttributes: ["data-attribute-with-dashes"]}, value: "<p id='p' data-attribute-with-dashes='123'>Click.</p><script>document.getElementById('p').dataset.attributeWithDashes=123;</script>", result: "<p id=\"p\">Click.</p><script></script>", message: "dropAttributes list [\"data-attribute-with-dashes\"] with dom dataset js access."},
];
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment