0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-01-09 15:31:53 +00:00

MOODLE-556: Fixed bugs in Math package revealed by tests

This commit is contained in:
Xavier Ripoll 2018-10-10 17:09:01 +02:00
parent 5a2a9d49f1
commit 0687cdc3d8

View File

@ -36,6 +36,23 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
// Prefix used for xlink attrs; is not specified by the MathML DTD // Prefix used for xlink attrs; is not specified by the MathML DTD
$E['XLINK.prefix'] = 'xlink'; $E['XLINK.prefix'] = 'xlink';
$proprietary_att_wrs = array(
'wrs:valign' => 'CDATA',
'wrs:columnalign' => 'CDATA',
'wrs:positionable' => 'CDATA',
'wrs:linecolor' => 'CDATA',
'wrs:baseline' => 'CDATA',
'wrs:reserved' => 'CDATA',
'wrs:decimalseparators' => 'CDATA'
// TODO: Add xmlns:wrs
);
$proprietary_att_dsi = array(
'xmlns:dsi' => 'Bool#http://www.dessci.com/mathml',
'dsi:background' => 'CDATA',
'dsi:color' => 'CDATA'
);
/***************************************************************** /*****************************************************************
* DTD code * DTD code
* Code from the DTD ported and adapted * Code from the DTD ported and adapted
@ -52,20 +69,25 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
$E['DefEncAtt'] = array( $E['DefEncAtt'] = array(
'encoding' => 'CDATA', 'encoding' => 'CDATA',
'definitionURL' => 'CDATA' 'definitionurl' => 'CDATA'
); );
$E['CommonAtt'] = array( $E['CommonAtt'] = array_merge(
'xmlns:mml' => 'Bool#http://www.w3.org/1998/Math/MathML', array(
$E['XLINK.prefix'] . ':href' => 'CDATA', 'xmlns' => 'Bool#http://www.w3.org/1998/Math/MathML',
$E['XLINK.prefix'] . ':type' => 'CDATA', $E['XLINK.prefix'] . ':href' => 'CDATA',
'xml:lang' => 'CDATA', $E['XLINK.prefix'] . ':type' => 'CDATA',
'xml:space' => 'Enum#default,preserve', 'xml:lang' => 'CDATA',
'id' => 'CDATA', // MathML allows multiple elements with same ID 'xml:space' => 'Enum#default,preserve',
'xref' => 'CDATA', 'id' => 'CDATA', // MathML allows multiple elements with same ID
'class' => 'CDATA', 'xref' => 'CDATA',
'href' => 'CDATA', 'class' => 'CDATA',
'other' => 'CDATA', 'style' => 'CDATA',
'href' => 'CDATA',
'other' => 'CDATA',
),
$proprietary_att_wrs,
$proprietary_att_dsi
); );
// These two sets of attrs appear commonly together. // These two sets of attrs appear commonly together.
@ -78,7 +100,7 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
$this->addElement( $this->addElement(
'cn', 'cn',
$default_display, $default_display,
'Custom: #PCDATA|mglyph|sep|' . $E['PresentationExpression'], 'Custom: (#PCDATA|mglyph|sep|' . $E['PresentationExpression'] . ')*',
array(), array(),
array_merge( array_merge(
$CDEAtt, $CDEAtt,
@ -92,7 +114,7 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
$this->addElement( $this->addElement(
'ci', 'ci',
$default_display, $default_display,
'Custom: #PCDATA|mglyph|' . $E['PresentationExpression'], 'Custom: (#PCDATA|mglyph|' . $E['PresentationExpression'] . ')*',
array(), array(),
array_merge( array_merge(
$CDEAtt, $CDEAtt,
@ -105,7 +127,7 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
$this->addElement( $this->addElement(
'csymbol', 'csymbol',
$default_display, $default_display,
'Custom: #PCDATA|mglyph|' . $E['PresentationExpression'], 'Custom: (#PCDATA|mglyph|' . $E['PresentationExpression'] . ')*',
array(), array(),
array_merge( array_merge(
$CDEAtt, $CDEAtt,
@ -169,6 +191,7 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
'|' . $E['lambda.mmlclass'] . '|' . $E['lambda.mmlclass'] .
'|' . $E['nary-functional.mmlclass'] . '|' . $E['nary-functional.mmlclass'] .
'|' . $E['binary-arith.mmlclass'] . '|' . $E['binary-arith.mmlclass'] .
'|' . $E['unary-arith.mmlclass'] .
'|' . $E['nary-minmax.mmlclass'] . '|' . $E['nary-minmax.mmlclass'] .
'|' . $E['nary-arith.mmlclass'] . '|' . $E['nary-arith.mmlclass'] .
'|' . $E['nary-logical.mmlclass'] . '|' . $E['nary-logical.mmlclass'] .
@ -240,7 +263,8 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
$this->addElement( $this->addElement(
'cbytes', 'cbytes',
$default_display, $default_display,
'Custom: (#PCDATA)', // The * is not in the DTD but we add it to allow empty tag
'Custom: (#PCDATA)*',
array(), array(),
$CDEAtt $CDEAtt
); );
@ -248,7 +272,8 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
$this->addElement( $this->addElement(
'cs', 'cs',
$default_display, $default_display,
'Custom: (#PCDATA)', // The * is not in the DTD but we add it to allow empty tag
'Custom: (#PCDATA)*',
array(), array(),
$CDEAtt $CDEAtt
); );
@ -1401,7 +1426,7 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
$E['MathExpression'] = $E['ContExp'] . $E['MathExpression'] = $E['ContExp'] .
'|' . $E['PresentationExpression']; '|' . $E['PresentationExpression'];
$E['ImpliedMrow'] = '(' . $E['MathExpression'] . ')'; $E['ImpliedMrow'] = '(' . $E['MathExpression'] . ')*';
$E['TableRowExpression'] = 'mtr|mlabeledtr'; $E['TableRowExpression'] = 'mtr|mlabeledtr';
$E['TableCellExpression'] = 'mtd'; $E['TableCellExpression'] = 'mtd';
$E['MstackExpression'] = $E['MathExpression'] . $E['MstackExpression'] = $E['MathExpression'] .
@ -1500,7 +1525,7 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
',badbreak', ',badbreak',
'lineleading' => $E['length'], 'lineleading' => $E['length'],
'linebreakstyle' => 'Enum#before,after,duplicate' . 'linebreakstyle' => 'Enum#before,after,duplicate' .
'infixlinebreakstyle', ',infixlinebreakstyle',
'linebreakmultchar' => 'CDATA', 'linebreakmultchar' => 'CDATA',
'indentalign' => 'Enum#left,center,right,auto,id', 'indentalign' => 'Enum#left,center,right,auto,id',
'indentshift' => $E['length'], 'indentshift' => $E['length'],
@ -1719,6 +1744,10 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
'bevelled' => 'Enum#true,false', 'bevelled' => 'Enum#true,false',
'charalign' => 'Enum#left,center,right', 'charalign' => 'Enum#left,center,right',
'charspacing' => 'CDATA', 'charspacing' => 'CDATA',
'close' => 'CDATA',
'columnalign' => 'CDATA',
'columnlines' => 'CDATA',
'columnspacing' => 'CDATA',
'columnspan' => $E['positive-integer'], 'columnspan' => $E['positive-integer'],
'columnwidth' => 'CDATA', 'columnwidth' => 'CDATA',
'crossout' => 'CDATA', 'crossout' => 'CDATA',
@ -1992,6 +2021,7 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
'frame' => $E['linestyle'], 'frame' => $E['linestyle'],
'framespacing' => 'CDATA', 'framespacing' => 'CDATA',
'equalrows' => 'Enum#true,false', 'equalrows' => 'Enum#true,false',
'equalcolumns' => 'Enum#true,false',
'displaystyle' => 'Enum#true,false', 'displaystyle' => 'Enum#true,false',
'side' => 'Enum#left,right,leftoverlap,rightoverlap', 'side' => 'Enum#left,right,leftoverlap,rightoverlap',
'minlabelspacing' => $E['length'] 'minlabelspacing' => $E['length']
@ -2080,7 +2110,7 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
$this->addElement( $this->addElement(
'msgroup', 'msgroup',
$default_display, $default_display,
'Custom: (' . $E['MstackExpression'] . ')', 'Custom: (' . $E['MstackExpression'] . ')*',
array(), array(),
$E['msgroup.attributes'] $E['msgroup.attributes']
); );
@ -2088,7 +2118,7 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
$this->addElement( $this->addElement(
'msrow', 'msrow',
$default_display, $default_display,
'Custom: (' . $E['MsrowExpression'] . ')', 'Custom: (' . $E['MsrowExpression'] . ')*',
array(), array(),
array_merge( array_merge(
$CCPAtt, $CCPAtt,
@ -2187,7 +2217,8 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
$this->addElement( $this->addElement(
'annotation', 'annotation',
$default_display, $default_display,
'Custom: (#PCDATA)', // The * is not in the DTD but we add it to allow empty tag
'Custom: (#PCDATA)*',
array(), array(),
$E['annotation.attributes'] $E['annotation.attributes']
); );
@ -2195,7 +2226,7 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
$this->addElement( $this->addElement(
'annotation-xml', 'annotation-xml',
$default_display, $default_display,
'Custom: (' . $E['MathExpression'] . ')*', 'Custom: ((' . $E['MathExpression'] . ')*)',
array(), array(),
$E['annotation.attributes'] $E['annotation.attributes']
); );
@ -2203,7 +2234,7 @@ class HTMLPurifier_HTMLModule_Math extends HTMLPurifier_HTMLModule
$this->addElement( $this->addElement(
'semantics', 'semantics',
$default_display, $default_display,
'Custom: (' . $E['MathExpression'] . 'Custom: ((' . $E['MathExpression'] .
'),(annotation|annotation-xml)*)', '),(annotation|annotation-xml)*)',
array(), array(),
array_merge( array_merge(