-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1945800 [wpt PR 50486] - [Sanitizer API] Update default handling …
…for comments and data-*., a=testonly Automatic update from web-platform-tests [Sanitizer API] Update default handling for comments and data-*. This tracks development of the spec: WICG/sanitizer-api#254 The PR makes the default for "comments:" and "dataAttributes:" keys in the configuration depend on whether this is for safe or unsafe use. That requires a bit of plumbing, since now the logic to interpret a config depends on a new flag. Also adds test cases. Bug: 356601280 Change-Id: I076c5418006b0dc35babbffd7d991e04c0f1d522 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6189121 Commit-Queue: Daniel Vogelheim <vogelheim@chromium.org> Reviewed-by: Yifan Luo <lyf@chromium.org> Cr-Commit-Position: refs/heads/main@{#1415510} -- wpt-commits: 07920967d79b3c88d440ddede3f7f5dc3b81c573 wpt-pr: 50486
- Loading branch information
1 parent
1e6734c
commit 8bcac47
Showing
5 changed files
with
94 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
testing/web-platform/tests/sanitizer-api/sanitizer-boolean-defaults.tentative.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Test boolean defaults in config per PR #254</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
// Test cases extracted from : https://github.com/WICG/sanitizer-api/pull/254 | ||
// | ||
// These are somewhat redundant with tests in sanitizer-config.tentative.html, | ||
// so maybe we can long-term merge them together. | ||
|
||
// Comments. | ||
test(t => { | ||
function try_unsafe(config) { | ||
const div = document.createElement("div"); | ||
div.setHTMLUnsafe("<!--bla-->", config) | ||
return div.innerHTML.includes("<!--"); | ||
} | ||
function try_safe(config) { | ||
const div = document.createElement("div"); | ||
div.setHTML("<!--bla-->", config) | ||
return div.innerHTML.includes("<!--"); | ||
} | ||
|
||
assert_true(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"); | ||
|
||
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"); | ||
|
||
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"); | ||
}, "comments"); | ||
|
||
// Data Attributes: | ||
test(t => { | ||
function try_unsafe(config) { | ||
const div = document.createElement("div"); | ||
div.setHTMLUnsafe("<div data-foo='bar'>", config) | ||
return div.innerHTML.includes("data-foo"); | ||
} | ||
function try_safe(config) { | ||
const div = document.createElement("div"); | ||
div.setHTML("<div data-foo='bar'>", config) | ||
return div.innerHTML.includes("data-foo"); | ||
} | ||
|
||
assert_true(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"); | ||
|
||
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"); | ||
|
||
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"); | ||
}, "data attributes"); | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters