jenkins-bot has submitted this change and it was merged.
Change subject: Add input checks for Language::sprintfDate()
......................................................................
Add input checks for Language::sprintfDate()
Check if the timestamp has a length of 14 characters and if it is numeric.
Throw an exception otherwise. Includes tests.
Bug: 47629
Change-Id: I9a4fd0af88cf20c2a6bd72fd7048743466c1600f
---
M languages/Language.php
M tests/phpunit/languages/LanguageTest.php
2 files changed, 34 insertions(+), 1 deletion(-)
Approvals:
Nikerabbit: Looks good to me, approved
jenkins-bot: Verified
diff --git a/languages/Language.php b/languages/Language.php
index 9651f3d..7ec37a1 100644
--- a/languages/Language.php
+++ b/languages/Language.php
@@ -1078,6 +1078,7 @@
* @param $zone DateTimeZone: Timezone of $ts
* @todo handling of "o" format character for Iranian, Hebrew, Hijri &
Thai?
*
+ * @throws MWException
* @return string
*/
function sprintfDate( $format, $ts, DateTimeZone $zone = null ) {
@@ -1093,6 +1094,15 @@
$thai = false;
$minguo = false;
$tenno = false;
+
+ if ( strlen( $ts ) !== 14 ) {
+ throw new MWException( __METHOD__ . ": The timestamp
$ts should have 14 characters" );
+ }
+
+ if ( !ctype_digit( $ts ) ) {
+ throw new MWException( __METHOD__ . ": The timestamp
$ts should be a number" );
+ }
+
for ( $p = 0; $p < strlen( $format ); $p++ ) {
$num = false;
$code = $format[$p];
diff --git a/tests/phpunit/languages/LanguageTest.php
b/tests/phpunit/languages/LanguageTest.php
index d5dbfb2..26bb2f3 100644
--- a/tests/phpunit/languages/LanguageTest.php
+++ b/tests/phpunit/languages/LanguageTest.php
@@ -1,7 +1,6 @@
<?php
class LanguageTest extends LanguageClassesTestCase {
-
function testLanguageConvertDoubleWidthToSingleWidth() {
$this->assertEquals(
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
@@ -500,6 +499,30 @@
}
/**
+ * Test too short timestamp
+ * @expectedException MWException
+ */
+ function testSprintfDateTooShortTimestamp() {
+ $this->getLang()->sprintfDate( 'xiY', '1234567890123' );
+ }
+
+ /**
+ * Test too long timestamp
+ * @expectedException MWException
+ */
+ function testSprintfDateTooLongTimestamp() {
+ $this->getLang()->sprintfDate( 'xiY', '123456789012345' );
+ }
+
+ /**
+ * Test too short timestamp
+ * @expectedException MWException
+ */
+ function testSprintfDateNotAllDigitTimestamp() {
+ $this->getLang()->sprintfDate( 'xiY', '-1234567890123' );
+ }
+
+ /**
* @dataProvider provideSprintfDateSamples
*/
function testSprintfDate( $format, $ts, $expected, $msg ) {
--
To view, visit https://gerrit.wikimedia.org/r/60798
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9a4fd0af88cf20c2a6bd72fd7048743466c1600f
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Siebrand <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: IAlex <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits