Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/193817
Change subject: Make PhpDateTimeParser fail if PHP changes the year
......................................................................
Make PhpDateTimeParser fail if PHP changes the year
This consolidates the previously existing check and always does it
when a year was found, no matter how many digits it haves.
Change-Id: I468c6020ba0a97dd060752a85ba0240a23313288
---
M lib/includes/parsers/PhpDateTimeParser.php
M lib/tests/phpunit/parsers/PhpDateTimeParserTest.php
2 files changed, 12 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/17/193817/1
diff --git a/lib/includes/parsers/PhpDateTimeParser.php
b/lib/includes/parsers/PhpDateTimeParser.php
index a14a554..d7d3205 100644
--- a/lib/includes/parsers/PhpDateTimeParser.php
+++ b/lib/includes/parsers/PhpDateTimeParser.php
@@ -89,15 +89,17 @@
// Parse using the DateTime object (this will allow us
to format the date in a nicer way)
$dateTime = new DateTime( $value );
+ // Fail if the DateTime object does calculations like
changing 2015-00-00 to 2014-12-30.
+ if ( $year !== null
+ && $dateTime->format( 'Y' ) !== str_pad(
substr( $year, -4 ), 4, '0', STR_PAD_LEFT )
+ ) {
+ throw new ParseException( $value . ' is not a
valid date.' );
+ }
+
if ( $year !== null && strlen( $year ) > 4 ) {
- // TODO: Fail if $dateTime->format( 'Y' ) !==
substr( $year, -4 )
$timeString = $sign . $year .
$dateTime->format( '-m-d\TH:i:s\Z' );
} else {
$timeString = $sign . $dateTime->format(
'Y-m-d\TH:i:s\Z' );
-
- if ( $year !== null && strpos( $timeString,
$year ) === false ) {
- throw new ParseException( $value . ' is
not a valid date.' );
- }
}
// Pass the reformatted string into a base parser that
parses this +/-Y-m-d\TH:i:s\Z format with a precision
diff --git a/lib/tests/phpunit/parsers/PhpDateTimeParserTest.php
b/lib/tests/phpunit/parsers/PhpDateTimeParserTest.php
index a4b6e0e..00cb739 100644
--- a/lib/tests/phpunit/parsers/PhpDateTimeParserTest.php
+++ b/lib/tests/phpunit/parsers/PhpDateTimeParserTest.php
@@ -210,9 +210,13 @@
'2015-07-101',
'10 .10 .2010',
'10...10...2010',
+ '00-00-00',
+ '99-00-00',
+ '111-00-00',
'2015-00-00',
+ '00000000099-00-00',
'00000002015-00-00',
- // FIXME: Should also fail for '92015-00-00'!
+ '92015-00-00',
'Jann 2014',
'1980x',
'1980s', // supported by MWTimeIsoParser
--
To view, visit https://gerrit.wikimedia.org/r/193817
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I468c6020ba0a97dd060752a85ba0240a23313288
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits