-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Guard more MathML-specific code with the MathMLCoreEnabled flag
After [1], MathMLElement instances are created even when MathMLCore is disabled. Particular attention was paid to the (previously incorrect) HasTagName(mathml_names::...) as well as to places where elements were cast to MathMLElement types. This CL performs the remaining work for callers of isMathMLElement(), checking possible behavior changes when MathMLCore is disabled for now. In details, these places are: 1. Adjustment of display: math on MathML elements. 2. Adjustment of display: contents on MathML elements. 3. Application of custom style to MathML elements. 4. Sanitization of MathML elements via the sanitizer API. For (1), there is already a guard in the CSS parser so there was no behavior change (cf isDisplayInside). An ASSERT is added to guarantee that. For (2), we don't resolve display: contents to none on MathML elements when MathMLCore is disabled, so they continue to behave the same as HTML elements. The code path for (3) performs dynamic casts to classes derived from MathMLElement, relying on generated implementations of AllowFrom(const Element&) that only check tag names. As a consequence this leads to incorrect casts when MathMLCore is disabled, since all MathML elements use the base MathMLElement class in that case. Finally for (4), we keep the changed implied by [1] to the FromAPI() function of sanitizer.cc i.e. the "math:" namespace designator is always appended for nodes in the MathML namespace, whether or not MathMLCore is enabled. Note that the Sanitizer API is not shipped yet so it's fine to do this web-exposed change without API owner approval. [1] https://chromium-review.googlesource.com/c/chromium/src/+/3506644 [2] https://source.chromium.org/search?q=mathml_element_type_helpers.h Bug: 6606, 1272556, 1307667 Change-Id: Ib069944e55e102381192d90c13c676fc2cb0b51d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3536908 Reviewed-by: Rune Lillesveen <futhark@chromium.org> Reviewed-by: Mason Freed <masonf@chromium.org> Commit-Queue: Frédéric Wang <fwang@igalia.com> Cr-Commit-Position: refs/heads/main@{#983716}
- Loading branch information
Showing
7 changed files
with
120 additions
and
28 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
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
23 changes: 23 additions & 0 deletions
23
third_party/blink/web_tests/virtual/mathml-disabled/display-values.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,23 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="../../resources/testharness.js"></script> | ||
<script src="../../resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<math id="math" style="display: math"></math> | ||
<math id="contents" style="display: contents"></math> | ||
<script> | ||
function getDisplayOf(id) { | ||
const style = window.getComputedStyle(document.getElementById(id)); | ||
return style.getPropertyValue("display"); | ||
} | ||
test(function() { | ||
assert_equals(getDisplayOf("math"), "inline"); | ||
}, "Computation of 'display: math' on MathML elements when MathML Core is disabled."); | ||
test(function() { | ||
assert_equals(getDisplayOf("contents"), "contents"); | ||
}, "Computation of 'display: contents' on MathML elements when MathML Core is disabled."); | ||
</script> | ||
</body> | ||
</html> |
3 changes: 3 additions & 0 deletions
3
third_party/blink/web_tests/virtual/mathml-disabled/mathml-core-elements-crash-expected.txt
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,3 @@ | ||
MathML elements should not cause any crash with MathMLCore disabled. | ||
|
||
|
42 changes: 42 additions & 0 deletions
42
third_party/blink/web_tests/virtual/mathml-disabled/mathml-core-elements-crash.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,42 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script> | ||
if (window.testRunner) | ||
testRunner.dumpAsText(); | ||
</script> | ||
</head> | ||
<body> | ||
<p>MathML elements should not cause any crash with MathMLCore disabled.</p> | ||
<math><annotation></annotation></math> | ||
<math><annotation-xml></annotation-xml></math> | ||
<math><maction></maction></math> | ||
<math><merror></merror></math> | ||
<math><mfrac></mfrac></math> | ||
<math><mi></mi></math> | ||
<math><mmultiscripts></mmultiscripts></math> | ||
<math><mn></mn></math> | ||
<math><mo></mo></math> | ||
<math><mover></mover></math> | ||
<math><mpadded></mpadded></math> | ||
<math><mphantom></mphantom></math> | ||
<math><mprescripts></mprescripts></math> | ||
<math><mroot></mroot></math> | ||
<math><mrow></mrow></math> | ||
<math><ms></ms></math> | ||
<math><mspace/></math> | ||
<math><msqrt></msqrt></math> | ||
<math><mstyle></mstyle></math> | ||
<math><msub></msub></math> | ||
<math><msubsup></msubsup></math> | ||
<math><msup></msup></math> | ||
<math><mtable></mtable></math> | ||
<math><mtd></mtd></math> | ||
<math><mtext></mtext></math> | ||
<math><mtr></mtr></math> | ||
<math><munder></munder></math> | ||
<math><munderover></munderover></math> | ||
<math><none/></math> | ||
<math><semantics></semantics></math> | ||
</body> | ||
</html> |
14 changes: 14 additions & 0 deletions
14
...arty/blink/web_tests/virtual/mathml-disabled/sanitizer-api-math-namespace-designator.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,14 @@ | ||
<!DOCTYPE html> | ||
<script src="../../resources/testharness.js"></script> | ||
<script src="../../resources/testharnessreport.js"></script> | ||
<script> | ||
const source = `<math><mtext>Hello</mtext></math>`; | ||
test(function() { | ||
const sanitizer = new Sanitizer({allowElements: ["math:math", "math:mtext"]}); | ||
assert_equals(sanitizer.sanitizeFor("template", source).innerHTML, source); | ||
}, `The 'math:' namespace designator allows to match MathML elements.`); | ||
test(function() { | ||
const sanitizer = new Sanitizer({allowElements: ["math", "mtext"]}); | ||
assert_equals(sanitizer.sanitizeFor("template", source).innerHTML, "Hello"); | ||
}, `The 'math:' namespace designator is required to match MathML elements.`); | ||
</script> |