jenkins-bot has submitted this change and it was merged.

Change subject: Reject out-of-range output when converting to TS_MW
......................................................................


Reject out-of-range output when converting to TS_MW

TS_MW is a 14-character string "YYYYMMDDHHIISS", and thus cannot
represent timestamps earlier than 00000101000000 or later than
99991231235959.

MWTimestamp should throw an exception if asked to represent out-of-range
times in this format, rather than returning invalid values that are
likely to be truncated by the database.

Bug: T51580
Change-Id: I744e446356f3ed9193dfaaaec5dc81c611dab4a3
---
M includes/MWTimestamp.php
M tests/phpunit/includes/MWTimestampTest.php
2 files changed, 28 insertions(+), 0 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/MWTimestamp.php b/includes/MWTimestamp.php
index 4b3d36a..ea91470 100644
--- a/includes/MWTimestamp.php
+++ b/includes/MWTimestamp.php
@@ -182,6 +182,11 @@
                        $output .= ' GMT';
                }
 
+               if ( $style == TS_MW && strlen( $output ) !== 14 ) {
+                       throw new TimestampException( __METHOD__ . ': The 
timestamp cannot be represented in ' .
+                               'the specified format' );
+               }
+
                return $output;
        }
 
diff --git a/tests/phpunit/includes/MWTimestampTest.php 
b/tests/phpunit/includes/MWTimestampTest.php
index 05c1a66..3656254 100644
--- a/tests/phpunit/includes/MWTimestampTest.php
+++ b/tests/phpunit/includes/MWTimestampTest.php
@@ -82,6 +82,17 @@
        }
 
        /**
+        * Test an out of range timestamp
+        * @dataProvider provideOutOfRangeTimestamps
+        * @expectedException TimestampException
+        * @covers MWTimestamp
+        */
+       public function testOutOfRangeTimestamps( $format, $input ) {
+               $timestamp = new MWTimestamp( $input );
+               $timestamp->getTimestamp( $format );
+       }
+
+       /**
         * Test requesting an invalid output format.
         * @expectedException TimestampException
         * @covers MWTimestamp::getTimestamp
@@ -114,6 +125,18 @@
        }
 
        /**
+        * Returns a list of out of range timestamps in the format:
+        * array( type, timestamp_of_type )
+        */
+       public static function provideOutOfRangeTimestamps() {
+               return array(
+                       // Various formats
+                       array( TS_MW, '-62167219201' ), // -0001-12-31T23:59:59Z
+                       array( TS_MW, '253402300800' ), // 10000-01-01T00:00:00Z
+               );
+       }
+
+       /**
         * @dataProvider provideHumanTimestampTests
         * @covers MWTimestamp::getHumanTimestamp
         */

-- 
To view, visit https://gerrit.wikimedia.org/r/181175
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I744e446356f3ed9193dfaaaec5dc81c611dab4a3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to