script: Add or remove elements in sanitizer (#44481)

Implement the `allowElement`, `removeElement` and
`replaceElementWithChildren` methods of the `Sanitizer` interface, which
add or remove elements in a sanitizer.

Specification:
- https://wicg.github.io/sanitizer-api/#dom-sanitizer-allowelement
- https://wicg.github.io/sanitizer-api/#dom-sanitizer-removeelement
-
https://wicg.github.io/sanitizer-api/#dom-sanitizer-replaceelementwithchildren

Testing: Covered by WPT tests in `sanitizer-api/` subdirectory.
Additionally, some tests in `sanitizer-basic-filtering.tentative.html`
are changed from ERROR to FAIL because of this implementation.
Fixes: Part of #43948

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
This commit is contained in:
Kingsley Yung
2026-04-24 23:07:01 +08:00
committed by GitHub
parent 93ae710c07
commit 430105468f
7 changed files with 842 additions and 90 deletions

View File

@@ -20,9 +20,9 @@ interface Sanitizer {
SanitizerConfig get();
// Modify a Sanitizer's lists and fields:
// boolean allowElement(SanitizerElementWithAttributes element);
// boolean removeElement(SanitizerElement element);
// boolean replaceElementWithChildren(SanitizerElement element);
boolean allowElement(SanitizerElementWithAttributes element);
boolean removeElement(SanitizerElement element);
boolean replaceElementWithChildren(SanitizerElement element);
// boolean allowAttribute(SanitizerAttribute attribute);
// boolean removeAttribute(SanitizerAttribute attribute);
// boolean setComments(boolean allow);