r98055 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98054‎ | r98055 | r98056 >
Date:04:08, 25 September 2011
Author:dantman
Status:ok (Comments)
Tags:
Comment:
Followup r94465 and r94465; Add phpunit tests for Sanitizer::fixDeprecatedAttributes and fix bugs related to clear="all" and mixed/uppercase attributes and values.
Modified paths:
  • /trunk/phase3/includes/Sanitizer.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/SanitizerTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/SanitizerTest.php
@@ -109,5 +109,22 @@
110110 $this->assertEquals( Sanitizer::decodeTagAttributes( 'foo=&"' ), array( 'foo' => '&"' ), 'Special chars can be provided as entities' );
111111 $this->assertEquals( Sanitizer::decodeTagAttributes( 'foo=&foobar;' ), array( 'foo' => '&foobar;' ), 'Entity-like items are accepted' );
112112 }
 113+
 114+ function testDeprecatedAttributes() {
 115+ $GLOBALS['wgCleanupPresentationalAttributes'] = true;
 116+ $this->assertEquals( Sanitizer::fixTagAttributes( 'clear="left"', 'br' ), ' style="clear: left;"', 'Deprecated attributes are converted to styles when enabled.' );
 117+ $this->assertEquals( Sanitizer::fixTagAttributes( 'clear="all"', 'br' ), ' style="clear: both;"', 'clear=all is converted to clear: both; not clear: all;' );
 118+ $this->assertEquals( Sanitizer::fixTagAttributes( 'CLEAR="ALL"', 'br' ), ' style="clear: both;"', 'clear=ALL is not treated differently from clear=all' );
 119+ $this->assertEquals( Sanitizer::fixTagAttributes( 'width="100"', 'td' ), ' style="width: 100px;"', 'Numeric sizes use pixels instead of numbers.' );
 120+ $this->assertEquals( Sanitizer::fixTagAttributes( 'width="100%"', 'td' ), ' style="width: 100%;"', 'Units are allowed in sizes.' );
 121+ $this->assertEquals( Sanitizer::fixTagAttributes( 'WIDTH="100%"', 'td' ), ' style="width: 100%;"', 'Uppercase WIDTH is treated as lowercase width.' );
 122+ $this->assertEquals( Sanitizer::fixTagAttributes( 'WiDTh="100%"', 'td' ), ' style="width: 100%;"', 'Mixed case does not break WiDTh.' );
 123+ $this->assertEquals( Sanitizer::fixTagAttributes( 'nowrap="true"', 'td' ), ' style="white-space: nowrap;"', 'nowrap attribute is output as white-space: nowrap; not something else.' );
 124+ $this->assertEquals( Sanitizer::fixTagAttributes( 'nowrap=""', 'td' ), ' style="white-space: nowrap;"', 'nowrap="" is considered true, not false' );
 125+ $this->assertEquals( Sanitizer::fixTagAttributes( 'NOWRAP="true"', 'td' ), ' style="white-space: nowrap;"', 'nowrap attribute works when uppercase.' );
 126+ $this->assertEquals( Sanitizer::fixTagAttributes( 'NoWrAp="true"', 'td' ), ' style="white-space: nowrap;"', 'nowrap attribute works when mixed-case.' );
 127+ $GLOBALS['wgCleanupPresentationalAttributes'] = false;
 128+ $this->assertEquals( Sanitizer::fixTagAttributes( 'clear="left"', 'br' ), ' clear="left"', 'Deprecated attributes are not converted to styles when enabled.' );
 129+ }
113130 }
114131
Index: trunk/phase3/includes/Sanitizer.php
@@ -641,6 +641,14 @@
642642 'width' => array( 'width', array_merge( array( 'hr', 'pre' ), $table, $cells, $colls ) ),
643643 );
644644
 645+ // Ensure that any upper case or mixed case attributes are converted to lowercase
 646+ foreach ( $attribs as $attribute => $value ) {
 647+ if ( $attribute !== strtolower( $attribute ) && array_key_exists( strtolower( $attribute ), $presentationalAttribs ) ) {
 648+ $attribs[strtolower( $attribute )] = $value;
 649+ unset( $attribs[$attribute] );
 650+ }
 651+ }
 652+
645653 $style = "";
646654 foreach ( $presentationalAttribs as $attribute => $info ) {
647655 list( $property, $elements ) = $info;
@@ -662,6 +670,11 @@
663671 $value = 'nowrap';
664672 }
665673
 674+ // clear="all" is clear: both; in css
 675+ if ( $attribute === 'clear' && strtolower( $value ) === 'all' ) {
 676+ $value = 'both';
 677+ }
 678+
666679 // Size based properties should have px applied to them if they have no unit
667680 if ( in_array( $attribute, array( 'height', 'width', 'size' ) ) ) {
668681 if ( preg_match( '/^[\d.]+$/', $value ) ) {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r94465Add code to the sanitizer to convert presontational attributes that were remo...dantman16:41, 14 August 2011

Comments

#Comment by Catrope (talk | contribs)   18:06, 25 September 2011
#Comment by Dantman (talk | contribs)   21:20, 25 September 2011

That would be r98053. And I can't reproduce either. Parser tests run perfectly and parser related phpunit tests run perfectly (other parts of phpunit break for me so I can't run all the tests, but I did the ones that look parser related). I even added r98056 to ensure that parser tests would run the same even if someone went into the config used by jenkins and disabled the presentational cleaning.

As far as I can tell, jenkins is what's broken, not MediaWiki or the tests.

#Comment by Catrope (talk | contribs)   06:44, 26 September 2011

Tests now succeed on Jenkins since r98103.

#Comment by Dantman (talk | contribs)   06:55, 26 September 2011

I curse the person who decided that when duplicating our parser test suite in phpunit he'd just copy the code parser tests used instead of moving them to a common area both suites could use and who decided not to load DefaultSettings.

Status & tagging log