Index: trunk/phase3/tests/phpunit/includes/media/FormatMetadataTest.php |
— | — | @@ -1,11 +1,17 @@ |
2 | 2 | <?php |
3 | 3 | class FormatMetadataTest extends MediaWikiTestCase { |
4 | 4 | public function testInvalidDate() { |
| 5 | + global $wgShowEXIF; |
| 6 | + if ( !$wgShowEXIF ) { |
| 7 | + $this->markTestIncomplete( "This test needs the exif extension." ); |
| 8 | + } |
| 9 | + |
5 | 10 | $file = UnregisteredLocalFile::newFromPath( dirname( __FILE__ ) . |
6 | 11 | '/broken_exif_date.jpg', 'image/jpeg' ); |
7 | 12 | |
8 | 13 | // Throws an error if bug hit |
9 | 14 | $meta = $file->formatMetadata(); |
| 15 | + $this->assertNotEquals( false, $meta, 'Valid metadata extracted' ); |
10 | 16 | |
11 | 17 | // Find date exif entry |
12 | 18 | $this->assertArrayHasKey( 'visible', $meta ); |
Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions.php/GlobalTest.php |
— | — | @@ -879,6 +879,12 @@ |
880 | 880 | // are less consistent. |
881 | 881 | ); |
882 | 882 | } |
| 883 | + |
| 884 | + public function testUnserialize() { |
| 885 | + $this->assertEquals( '', wfUnserialize( 's:0:"";') ); |
| 886 | + $this->assertEquals( false, wfUnserialize( '0' ), |
| 887 | + 'Invalid input to unserialize()' ); |
| 888 | + } |
883 | 889 | |
884 | 890 | /* TODO: many more! */ |
885 | 891 | } |
Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -3549,3 +3549,17 @@ |
3550 | 3550 | function wfRunHooks( $event, $args = array() ) { |
3551 | 3551 | return Hooks::run( $event, $args ); |
3552 | 3552 | } |
| 3553 | + |
| 3554 | +/** |
| 3555 | + * Unserialize a string to a PHP value without throwing E_NOTICE. Simply a |
| 3556 | + * wrapper around unserialize() |
| 3557 | + * |
| 3558 | + * @param $data string The serialized string |
| 3559 | + * @return mixed |
| 3560 | + */ |
| 3561 | +function wfUnserialize( $data ) { |
| 3562 | + wfSuppressWarnings(); |
| 3563 | + $result = unserialize( $data ); |
| 3564 | + wfRestoreWarnings(); |
| 3565 | + return $result; |
| 3566 | +} |
Index: trunk/phase3/includes/media/ExifBitmap.php |
— | — | @@ -109,7 +109,7 @@ |
110 | 110 | return false; |
111 | 111 | } |
112 | 112 | |
113 | | - $exif = unserialize( $metadata ); |
| 113 | + $exif = wfUnserialize( $metadata ); |
114 | 114 | if ( !$exif ) { |
115 | 115 | return false; |
116 | 116 | } |