Skip to content

Commit

Permalink
[Sanitizer] Implement config and defaultConfig as attributes.
Browse files Browse the repository at this point in the history
This follows spec discussion at github.com/WICG/sanitizer-api/issues/92

Bug: 1213893
Change-Id: I9b7102fecd7f896b5cec160592a5d6bd60c16716
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2996826
Commit-Queue: Daniel Vogelheim <[email protected]>
Reviewed-by: Yifan Luo <[email protected]>
Cr-Commit-Position: refs/heads/master@{#898870}
NOKEYCHECK=True
GitOrigin-RevId: e3d90a7ac52a6cd8dee48218f4e5e1de9beac565
  • Loading branch information
otherdaniel authored and copybara-github committed Jul 6, 2021
1 parent a2f42bf commit 0fdcd60
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions blink/renderer/modules/sanitizer_api/sanitizer.idl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ typedef (DOMString or TrustedHTML or DocumentFragment or Document) SanitizerInpu
[MeasureAs=SanitizerAPIToFragment, CallWith=ScriptState, RaisesException] DocumentFragment sanitize(SanitizerInputWithTrustedHTML input);
[MeasureAs=SanitizerAPIToString, CallWith=ScriptState, RaisesException] DOMString sanitizeToString(SanitizerInput input);

[MeasureAs=SanitizerAPIGetConfig] SanitizerConfig config();
[MeasureAs=SanitizerAPIGetDefaultConfig] static SanitizerConfig defaultConfig();
[MeasureAs=SanitizerAPIGetConfig] readonly attribute SanitizerConfig config;
[MeasureAs=SanitizerAPIGetDefaultConfig] static readonly attribute SanitizerConfig defaultConfig;
};
Original file line number Diff line number Diff line change
Expand Up @@ -8148,9 +8148,9 @@ interface SVGViewElement : SVGElement
method constructor
setter zoomAndPan
interface Sanitizer
static method defaultConfig
static getter defaultConfig
attribute @@toStringTag
method config
getter config
method constructor
method sanitize
method sanitizeToString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@

test(t => {
// Quick sanity test: Test a few default values.
assert_in_array("div", Sanitizer.defaultConfig().allowElements);
assert_false(Sanitizer.defaultConfig().allowElements.includes("script"));
assert_false(Sanitizer.defaultConfig().allowElements.includes("noscript"));
assert_in_array("div", Sanitizer.defaultConfig.allowElements);
assert_false(Sanitizer.defaultConfig.allowElements.includes("script"));
assert_false(Sanitizer.defaultConfig.allowElements.includes("noscript"));

assert_true("span" in Sanitizer.defaultConfig().allowAttributes);
assert_false("onclick" in Sanitizer.defaultConfig().allowAttributes);
assert_true("span" in Sanitizer.defaultConfig.allowAttributes);
assert_false("onclick" in Sanitizer.defaultConfig.allowAttributes);

assert_false("dropElements" in Sanitizer.defaultConfig());
assert_false("blockElements" in Sanitizer.defaultConfig());
assert_false("dropAttributes" in Sanitizer.defaultConfig());
assert_false(Sanitizer.defaultConfig().allowCustomElements);
}, "SanitizerAPI defaultConfig()");
assert_false("dropElements" in Sanitizer.defaultConfig);
assert_false("blockElements" in Sanitizer.defaultConfig);
assert_false("dropAttributes" in Sanitizer.defaultConfig);
assert_false(Sanitizer.defaultConfig.allowCustomElements);
}, "SanitizerAPI defaultConfig");

test(t => {
assert_deep_equals(Sanitizer.defaultConfig(),
new Sanitizer().config());
}, "SanitizerAPI config() on default created Sanitizer");
assert_deep_equals(Sanitizer.defaultConfig,
new Sanitizer().config);
}, "SanitizerAPI config on default created Sanitizer");

test(t => {
const configs = [{
Expand All @@ -52,8 +52,8 @@
allowCustomElements: false,
}];
for (const config of configs)
assert_deep_equals(config, new Sanitizer(config).config());
}, "SanitizerAPI config() reflects creation config.");
assert_deep_equals(config, new Sanitizer(config).config);
}, "SanitizerAPI config reflects creation config.");
</script>
</body>
</html>

0 comments on commit 0fdcd60

Please sign in to comment.