File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -637,6 +637,14 @@ impl CanonicalizeContext {
637637 } ,
638638 }
639639 }
640+ if matches ! ( element_name, "mtd" | "mtr" | "mlabeledtr" ) {
641+ let parent_name = name ( get_parent ( mathml) ) ;
642+ if ( element_name == "mtr" || element_name == "mlabeledtr" ) && parent_name != "mtable" {
643+ bail ! ( "Illegal MathML: {} is not a child of mtable. Parent is {}" , element_name, mml_to_string( get_parent( mathml) ) ) ;
644+ } else if element_name == "mtd" && ( parent_name != "mtr" || parent_name != "mlabeledtr" ) {
645+ bail ! ( "Illegal MathML: mtd is not a child of {}. Parent is {}" , parent_name, mml_to_string( get_parent( mathml) ) ) ;
646+ }
647+ }
640648 let children = mathml. children ( ) ;
641649 if element_name == "semantics" {
642650 if children. is_empty ( ) {
@@ -4747,6 +4755,38 @@ mod canonicalize_tests {
47474755 assert ! ( canonicalize( mathml) . is_err( ) ) ;
47484756 }
47494757
4758+ #[ test]
4759+ fn illegal_mtd_element ( ) {
4760+ use crate :: interface:: * ;
4761+ let test_str = "<math>
4762+ <mtable>
4763+ <mtr>
4764+ <mtd>
4765+ <mtext></mtext>
4766+ </mtd>
4767+ <mtd>
4768+ <mrow>
4769+ <mi>E</mi>
4770+ <mo>=</mo>
4771+ <mrow>
4772+ <mi>m</mi>
4773+ <mo><!--INVISIBLE TIMES--></mo>
4774+ <msup>
4775+ <mi>c</mi>
4776+ <mn>2</mn>
4777+ </msup>
4778+ </mrow>
4779+ </mrow>
4780+ </mtd>
4781+ </mtr>
4782+ </mtable>
4783+ </math>" ;
4784+ let package1 = & parser:: parse ( test_str) . expect ( "Failed to parse test input" ) ;
4785+ let mathml = get_element ( package1) ;
4786+ trim_element ( mathml, false ) ;
4787+ assert ! ( canonicalize( mathml) . is_err( ) ) ;
4788+ }
4789+
47504790
47514791 #[ test]
47524792 fn a_to_mrow ( ) -> Result < ( ) > {
You can’t perform that action at this time.
0 commit comments