From 99159fd750eabc37032aa5111ebc6c79c054663a Mon Sep 17 00:00:00 2001 From: umherirrender Date: Fri, 14 Sep 2012 18:28:22 +0200 Subject: [PATCH] wfTimestamp should not die on bogus input [Regression] 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: Change-Id: I1e8c785941d35678f3d12824bdde0ce245572592 --- includes/GlobalFunctions.php | 9 +++++++-- .../phpunit/includes/media/BitmapMetadataHandlerTest.php | 1 - 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 4080e466ab..17e3f4d5a0 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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; + } } /** diff --git a/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php b/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php index b604d59041..88f87ef9e3 100644 --- a/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php +++ b/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php @@ -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 . -- 2.20.1