(bug 29408) Key 'something.' is not in a proper format
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 18 Jun 2011 14:56:14 +0000 (14:56 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 18 Jun 2011 14:56:14 +0000 (14:56 +0000)
Fixed this by relaxing the stash key regex. For some files MediaWiki is simply not able to guess an extension. If the wiki has been configured to allow them, we should just let them pass in the stash as well.

includes/upload/UploadStash.php
tests/phpunit/includes/upload/UploadStashTest.php [new file with mode: 0644]

index 2412643..f926584 100644 (file)
@@ -14,7 +14,7 @@
 class UploadStash {
 
        // Format of the key for files -- has to be suitable as a filename itself (e.g. ab12cd34ef.jpg)
-       const KEY_FORMAT_REGEX = '/^[\w-]+\.\w+$/';
+       const KEY_FORMAT_REGEX = '/^[\w-]+\.\w*$/';
 
        /**
         * repository that this uses to store temp files
diff --git a/tests/phpunit/includes/upload/UploadStashTest.php b/tests/phpunit/includes/upload/UploadStashTest.php
new file mode 100644 (file)
index 0000000..c34714a
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+class UploadStashTest extends MediaWikiTestCase {
+       public function setUp() {
+               parent::setUp();
+               
+               // Setup a fake session if necessary
+               if ( !isset( $_SESSION ) ) {
+                       $GLOBALS['_SESSION'] = array();
+               }
+               
+               // Setup a file for bug 29408
+               $this->bug29408File = dirname( __FILE__ ) . '/bug29408';
+               file_put_contents( $this->bug29408File, "\x00" );               
+       }
+       
+       public function testBug29408() {
+               $repo = RepoGroup::singleton()->getLocalRepo();
+               $stash = new UploadStash( $repo );
+               
+               // Throws exception caught by PHPUnit on failure
+               $file = $stash->stashFile( $this->bug29408File );
+               // We'll never reach this point if we hit bug 29408
+               $this->assertTrue( true, 'Unrecognized file without extension' );
+               
+               $file->remove();
+       }
+       
+       public function tearDown() {
+               parent::tearDown();
+               
+               unlink( $this->bug29408File );
+               
+       }
+}
\ No newline at end of file