commit 387a0a054e626f840f5023c97fbb1c8d56136c2b
parent 3144a3ec6625f88956d16e6bd7dd67f084f32f28
Author: Daniel Vogelheim <30862698+otherdaniel@users.noreply.github.com>
Date: Fri, 14 Nov 2025 10:23:36 +0000
Bug 1999284 [wpt PR 55959] - Update sanitizer-boolean-defaults to match current spec., a=testonly
Automatic update from web-platform-tests
Update sanitizer-boolean-defaults to match current spec. (#55959)
* Update sanitizer-boolean-defaults to match current spec.
* Add test cases for attributes:, but without dataAttributes:
--
wpt-commits: 676bf0e691c1173ddbe454056048278cd63a0566
wpt-pr: 55959
Diffstat:
1 file changed, 46 insertions(+), 24 deletions(-)
diff --git a/testing/web-platform/tests/sanitizer-api/sanitizer-boolean-defaults.tentative.html b/testing/web-platform/tests/sanitizer-api/sanitizer-boolean-defaults.tentative.html
@@ -25,20 +25,25 @@ test(t => {
return div.innerHTML.includes("<!--");
}
- assert_false(new Sanitizer().get().comments, "1");
- assert_true(new Sanitizer({}).get().comments, "2");
- assert_true(new Sanitizer({comments: true}).get().comments, "3");
- assert_false(new Sanitizer({comments: false}).get().comments, "4");
+ // Parameter-less constructor.
+ assert_false(new Sanitizer().get().comments);
+ assert_true(try_unsafe());
+ assert_false(try_safe());
- assert_true(try_unsafe(), "5");
- assert_true(try_unsafe({sanitizer:{}}), "6");
- assert_true(try_unsafe({sanitizer:{comments:true}}), "7");
- assert_false(try_unsafe({sanitizer:{comments:false}}), "8");
+ // Constructed from empty dictionary.
+ assert_true(new Sanitizer({}).get().comments);
+ assert_true(try_unsafe({sanitizer:{}}));
+ assert_false(try_safe({sanitizer:{}}));
- assert_false(try_safe(), "9");
- assert_false(try_safe({sanitizer:{}}), "10");
- assert_true(try_safe({sanitizer:{comments:true}}), "11");
- assert_false(try_safe({sanitizer:{comments:false}}), "12");
+ // Explicitly set to true.
+ assert_true(new Sanitizer({comments: true}).get().comments);
+ assert_true(try_unsafe({sanitizer:{comments:true}}));
+ assert_true(try_safe({sanitizer:{comments:true}}));
+
+ // Explicitly set to false.
+ assert_false(new Sanitizer({comments: false}).get().comments);
+ assert_false(try_unsafe({sanitizer:{comments:false}}));
+ assert_false(try_safe({sanitizer:{comments:false}}));
}, "comments");
// Data Attributes:
@@ -54,20 +59,37 @@ test(t => {
return div.innerHTML.includes("data-foo");
}
- assert_false(new Sanitizer().get().dataAttributes, "1");
- assert_true(new Sanitizer({}).get().dataAttributes, "2");
- assert_true(new Sanitizer({dataAttributes: true}).get().dataAttributes, "3");
- assert_false(new Sanitizer({dataAttributes: false}).get().dataAttributes, "4");
+ // Parameter-less constructor.
+ assert_false(new Sanitizer().get().dataAttributes);
+ assert_true(try_unsafe());
+ assert_false(try_safe());
+
+ // Constructed from empty dictionary: Canonicalization removes dataAttributes.
+ assert_equals(undefined, new Sanitizer({}).get().dataAttributes);
+ assert_true(try_unsafe({sanitizer:{}}));
+ assert_true(try_safe({sanitizer:{}}));
+
+ // Explicitly set to true.
+ const dataAttributes_is_true = {attributes:[], dataAttributes: true};
+ assert_true(new Sanitizer(dataAttributes_is_true).get().dataAttributes);
+ assert_true(try_unsafe({sanitizer:dataAttributes_is_true}));
+ assert_true(try_safe({sanitizer:dataAttributes_is_true}));
- assert_true(try_unsafe(), "5");
- assert_true(try_unsafe({sanitizer:{}}), "6");
- assert_true(try_unsafe({sanitizer:{dataAttributes:true}}), "7");
- assert_false(try_unsafe({sanitizer:{dataAttributes:false}}), "8");
+ // Explicitly set to false.
+ const dataAttributes_is_false = {attributes:[], dataAttributes: false};
+ assert_false(new Sanitizer(dataAttributes_is_false).get().dataAttributes);
+ assert_false(try_unsafe({sanitizer:dataAttributes_is_false}));
+ assert_false(try_safe({sanitizer:dataAttributes_is_false}));
- assert_false(try_safe(), "9");
- assert_false(try_safe({sanitizer:{}}), "10");
- assert_true(try_safe({sanitizer:{dataAttributes:true}}), "11");
- assert_false(try_safe({sanitizer:{dataAttributes:false}}), "12");
+ // dataAttributes not set.
+ // (This case is different from the "empty dictionary" case above, because
+ // constructing from an empty dictionary adds a removeAttributes key and thus
+ // dataAttributes is removed, too. But this case has an explicit attributes
+ // key and thus dataAttributes should be added by the canonicalization.)
+ const dataAttributes_is_not_set = {attributes:[]};
+ assert_true(new Sanitizer(dataAttributes_is_not_set).get().dataAttributes);
+ assert_true(try_unsafe({sanitizer:dataAttributes_is_not_set}));
+ assert_false(try_safe({sanitizer:dataAttributes_is_not_set}));
}, "data attributes");
</script>