jenkins-bot has submitted this change and it was merged.
Change subject: Always pad year to 4 digits in DateTime diffs
......................................................................
Always pad year to 4 digits in DateTime diffs
Change-Id: I6f017772fb30324d3039cf89ead3d840e3a4bf0a
---
M lib/includes/formatters/TimeDetailsFormatter.php
M lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
2 files changed, 12 insertions(+), 5 deletions(-)
Approvals:
Daniel Kinzler: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/includes/formatters/TimeDetailsFormatter.php
b/lib/includes/formatters/TimeDetailsFormatter.php
index 0d48da6..f4f537a 100644
--- a/lib/includes/formatters/TimeDetailsFormatter.php
+++ b/lib/includes/formatters/TimeDetailsFormatter.php
@@ -101,8 +101,15 @@
* @return string HTML
*/
private function getTimeHtml( $time ) {
- // Drop the trailing "Z".
- return htmlspecialchars( preg_replace( '/(?<=\d)Z$/i', '',
$time ) );
+ // Loose check if the ISO-like string contains at least year,
month, day and hour.
+ if ( !preg_match( '/^([-+])(\d+)(-\d+-\d+T\d+(?::\d+)*)Z?$/i',
$time, $matches ) ) {
+ return htmlspecialchars( $time );
+ }
+
+ // Warning, never cast the year to integer to not run into
32-bit integer overflows!
+ $year = ltrim( $matches[2], '0' );
+ // Keep the sign. Pad the year. Keep month, day, and time. Drop
the trailing "Z".
+ return htmlspecialchars( $matches[1] . str_pad( $year, 4, '0',
STR_PAD_LEFT ) . $matches[3] );
}
/**
diff --git a/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
b/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
index b522815..2cd60e1 100644
--- a/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
+++ b/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
@@ -57,11 +57,11 @@
),
array(
new TimeValue( '+999-01-01T00:00:00Z', 0, 0, 0,
$day, $gregorian ),
-
'@.*<td[^<>]*isotime">\+999-01-01T00:00:00</td>.*@s'
+
'@.*<td[^<>]*isotime">\+0999-01-01T00:00:00</td>.*@s'
),
array(
- new TimeValue( '+099999-01-01T00:00:00Z', 0, 0,
0, $day, $gregorian ),
-
'@.*<td[^<>]*isotime">\+099999-01-01T00:00:00</td>.*@s'
+ new TimeValue( '-099999-01-01T00:00:00Z', 0, 0,
0, $day, $gregorian ),
+
'@.*<td[^<>]*isotime">-99999-01-01T00:00:00</td>.*@s'
),
array(
new TimeValue( '+2001-01-01T00:00:00Z', 0, 0,
0, $day, TimeFormatter::CALENDAR_JULIAN ),
--
To view, visit https://gerrit.wikimedia.org/r/191640
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6f017772fb30324d3039cf89ead3d840e3a4bf0a
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits