From: Kunal Mehta Date: Sun, 23 Sep 2018 18:58:14 +0000 (-0700) Subject: SpecialLog: Don't throw exceptions on invalid date from user input X-Git-Tag: 1.34.0-rc.0~4010^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=f198154d767824e3ade13e39774f20641917674e SpecialLog: Don't throw exceptions on invalid date from user input If users provide invalid input to the date option on Special:Log (most likely an intentional thing given the calendar input widget), don't let the TimestampException bubble up - just discard the invalid date. Integration test included, which fails without this patch. Bug: T201411 Change-Id: Ie1a9a84343ae4e78e076586f759917e5fd5af33c --- diff --git a/includes/specials/SpecialLog.php b/includes/specials/SpecialLog.php index d700c397d6..54afde182d 100644 --- a/includes/specials/SpecialLog.php +++ b/includes/specials/SpecialLog.php @@ -21,6 +21,8 @@ * @ingroup SpecialPage */ +use Wikimedia\Timestamp\TimestampException; + /** * A special page that lists log entries * @@ -63,10 +65,18 @@ class SpecialLog extends SpecialPage { // Set date values $dateString = $this->getRequest()->getVal( 'wpdate' ); if ( !empty( $dateString ) ) { - $dateStamp = MWTimestamp::getInstance( $dateString . ' 00:00:00' ); - $opts->setValue( 'year', (int)$dateStamp->format( 'Y' ) ); - $opts->setValue( 'month', (int)$dateStamp->format( 'm' ) ); - $opts->setValue( 'day', (int)$dateStamp->format( 'd' ) ); + try { + $dateStamp = MWTimestamp::getInstance( $dateString . ' 00:00:00' ); + } catch ( TimestampException $e ) { + // If users provide an invalid date, silently ignore it + // instead of letting an exception bubble up (T201411) + $dateStamp = false; + } + if ( $dateStamp ) { + $opts->setValue( 'year', (int)$dateStamp->format( 'Y' ) ); + $opts->setValue( 'month', (int)$dateStamp->format( 'm' ) ); + $opts->setValue( 'day', (int)$dateStamp->format( 'd' ) ); + } } # Don't let the user get stuck with a certain date diff --git a/tests/phpunit/includes/specials/SpecialLogTest.php b/tests/phpunit/includes/specials/SpecialLogTest.php new file mode 100644 index 0000000000..d66280e65c --- /dev/null +++ b/tests/phpunit/includes/specials/SpecialLogTest.php @@ -0,0 +1,35 @@ +executeSpecialPage( + '', + // There is no 13th month + new FauxRequest( [ 'wpdate' => '2018-13-01' ] ), + 'qqx' + ); + $this->assertContains( '(log-summary)', $html ); + } + +}