From: Antoine Musso Date: Mon, 17 Sep 2012 20:16:34 +0000 (+0200) Subject: (bug 40306) Only convert align to float for table. X-Git-Tag: 1.31.0-rc.0~22346^2 X-Git-Url: http://git.cyclocoop.org/ecrire?a=commitdiff_plain;h=218d50c0c3ba3af7843bff32fca9f1eec74925b6;p=lhc%2Fweb%2Fwiklou.git (bug 40306) Only convert align to float for table. Align should be converted to text-align for all the elements specified in $presentationalAttribs mapping. Table however is an exception, it applies to alignment of the block (instead of the content). Follow up I108cbd10 / 27a4d74bd7. Change-Id: Iee17d4ef1a6a9b46d88a330cfc9179bccfe93247 --- diff --git a/includes/Sanitizer.php b/includes/Sanitizer.php index 734c4ec9de..224b2d1247 100644 --- a/includes/Sanitizer.php +++ b/includes/Sanitizer.php @@ -692,7 +692,9 @@ class Sanitizer { } } - if ( $attribute === 'align' && !in_array( $element, $cells ) ) { + // Table align is special, it's about block alignment instead of + // content align (see also bug 40306) + if ( $attribute === 'align' && in_array( $element, $table ) ) { if ( $value === 'center' ) { $style .= ' margin-left: auto;'; $property = 'margin-right'; diff --git a/tests/phpunit/includes/SanitizerTest.php b/tests/phpunit/includes/SanitizerTest.php index c9299893c1..d67f905942 100644 --- a/tests/phpunit/includes/SanitizerTest.php +++ b/tests/phpunit/includes/SanitizerTest.php @@ -136,10 +136,26 @@ class SanitizerTest extends MediaWikiTestCase { array( 'nowrap=""', 'td', ' style="white-space: nowrap;"', 'nowrap="" is considered true, not false' ), array( 'NOWRAP="true"', 'td', ' style="white-space: nowrap;"', 'nowrap attribute works when uppercase.' ), array( 'NoWrAp="true"', 'td', ' style="white-space: nowrap;"', 'nowrap attribute works when mixed-case.' ), - array( 'align="right"', 'td', ' style="text-align: right;"', 'align on table cells gets converted to text-align' ), - array( 'align="center"', 'td', ' style="text-align: center;"', 'align on table cells gets converted to text-align' ), - array( 'align="left"', 'div', ' style="float: left;"', 'align=(left|right) on non-cells gets converted to float' ), - array( 'align="center"', 'div', ' style="margin-left: auto; margin-right: auto;"', 'align="center" on non-cells' ), + array( 'align="right"', 'td', ' style="text-align: right;"' , 'align on table cells gets converted to text-align' ), + array( 'align="center"', 'td', ' style="text-align: center;"' , 'align on table cells gets converted to text-align' ), + array( 'align="left"' , 'div', ' style="text-align: left;"' , 'align=(left|right) on div elements gets converted to text-align' ), + array( 'align="center"', 'div', ' style="text-align: center;"', 'align="center" on div elements gets converted to text-align' ), + array( 'align="left"' , 'p', ' style="text-align: left;"' , 'align on p elements gets converted to text-align' ), + array( 'align="left"' , 'h1', ' style="text-align: left;"' , 'align on h1 elements gets converted to text-align' ), + array( 'align="left"' , 'h1', ' style="text-align: left;"' , 'align on h1 elements gets converted to text-align' ), + array( 'align="left"' , 'caption',' style="text-align: left;"','align on caption elements gets converted to text-align' ), + array( 'align="left"' , 'tfoot',' style="text-align: left;"' , 'align on tfoot elements gets converted to text-align' ), + array( 'align="left"' , 'tbody',' style="text-align: left;"' , 'align on tbody elements gets converted to text-align' ), + + # + array( 'align="right"' , 'tr', ' style="text-align: right;"' , 'align on table row get converted to text-align' ), + array( 'align="center"', 'tr', ' style="text-align: center;"', 'align on table row get converted to text-align' ), + array( 'align="left"' , 'tr', ' style="text-align: left;"' , 'align on table row get converted to text-align' ), + + #table + array( 'align="left"' , 'table', ' style="float: left;"' , 'align on table converted to float' ), + array( 'align="center"', 'table', ' style="margin-left: auto; margin-right: auto;"', 'align center on table converted to margins' ), + array( 'align="right"' , 'table', ' style="float: right;"' , 'align on table converted to float' ), ); }