Index: trunk/phase3/tests/phpunit/includes/SanitizerTest.php |
— | — | @@ -109,5 +109,22 @@ |
110 | 110 | $this->assertEquals( Sanitizer::decodeTagAttributes( 'foo=&"' ), array( 'foo' => '&"' ), 'Special chars can be provided as entities' ); |
111 | 111 | $this->assertEquals( Sanitizer::decodeTagAttributes( 'foo=&foobar;' ), array( 'foo' => '&foobar;' ), 'Entity-like items are accepted' ); |
112 | 112 | } |
| 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 | + } |
113 | 130 | } |
114 | 131 | |
Index: trunk/phase3/includes/Sanitizer.php |
— | — | @@ -641,6 +641,14 @@ |
642 | 642 | 'width' => array( 'width', array_merge( array( 'hr', 'pre' ), $table, $cells, $colls ) ), |
643 | 643 | ); |
644 | 644 | |
| 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 | + |
645 | 653 | $style = ""; |
646 | 654 | foreach ( $presentationalAttribs as $attribute => $info ) { |
647 | 655 | list( $property, $elements ) = $info; |
— | — | @@ -662,6 +670,11 @@ |
663 | 671 | $value = 'nowrap'; |
664 | 672 | } |
665 | 673 | |
| 674 | + // clear="all" is clear: both; in css |
| 675 | + if ( $attribute === 'clear' && strtolower( $value ) === 'all' ) { |
| 676 | + $value = 'both'; |
| 677 | + } |
| 678 | + |
666 | 679 | // Size based properties should have px applied to them if they have no unit |
667 | 680 | if ( in_array( $attribute, array( 'height', 'width', 'size' ) ) ) { |
668 | 681 | if ( preg_match( '/^[\d.]+$/', $value ) ) { |