wfTimestamp should not die on bogus input [Regression]
authorumherirrender <umherirrender_de.wp@web.de>
Fri, 14 Sep 2012 16:28:22 +0000 (18:28 +0200)
committerumherirrender <umherirrender_de.wp@web.de>
Fri, 14 Sep 2012 16:28:22 +0000 (18:28 +0200)
Followup I68eb9f27

No caller of wfTimestamp can handle the exception, false is always used,
as the method comment says.

See bug 40037 for File related timestamps.
The api result is also not b/c:
<api servedby="mw70">
  <error code="internal_api_error_TimestampException" info="Exception
Caught: MWTimestamp::setTimestamp : Invalid timestamp - te"
xml:space="preserve" />
</api>

Change-Id: I1e8c785941d35678f3d12824bdde0ce245572592

includes/GlobalFunctions.php
tests/phpunit/includes/media/BitmapMetadataHandlerTest.php

index 4080e46..17e3f4d 100644 (file)
@@ -2409,8 +2409,13 @@ define( 'TS_ISO_8601_BASIC', 9 );
  * @return Mixed: String / false The same date in the format specified in $outputtype or false
  */
 function wfTimestamp( $outputtype = TS_UNIX, $ts = 0 ) {
-       $timestamp = new MWTimestamp( $ts );
-       return $timestamp->getTimestamp( $outputtype );
+       try {
+               $timestamp = new MWTimestamp( $ts );
+               return $timestamp->getTimestamp( $outputtype );
+       } catch( TimestampException $e ) {
+               wfDebug("wfTimestamp() fed bogus time value: TYPE=$outputtype; VALUE=$ts\n");
+               return false;
+       }
 }
 
 /**
index b604d59..88f87ef 100644 (file)
@@ -76,7 +76,6 @@ class BitmapMetadataHandlerTest extends MediaWikiTestCase {
        /**
         * File has an invalid time (+ one valid but really weird time)
         * that shouldn't be included
-        * @expectedException TimestampException
         */
        public function testIPTCDatesInvalid() {
                $meta = BitmapMetadataHandler::Jpeg( $this->filePath .