Daniel Kinzler has uploaded a new change for review.
https://gerrit.wikimedia.org/r/67962
Change subject: (bug 49264, bug 48965) validate time format.
......................................................................
(bug 49264, bug 48965) validate time format.
This provides validation of the provided date/time string
when constructing a TimeValue object.
This is a rough, manual backport of I6990983e, to serve as
a hot fix for bug 49425.
Change-Id: I6990983ef0c0cad7c9d4f271bdf803902b94230b
---
M DataValues/includes/values/TimeValue.php
M DataValues/tests/phpunit/includes/values/TimeValueTest.php
2 files changed, 24 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues
refs/changes/62/67962/1
diff --git a/DataValues/includes/values/TimeValue.php
b/DataValues/includes/values/TimeValue.php
index 6b58e60..bed91db 100644
--- a/DataValues/includes/values/TimeValue.php
+++ b/DataValues/includes/values/TimeValue.php
@@ -125,6 +125,10 @@
throw new InvalidArgumentException( '$time needs to be
a string' );
}
+ if ( !preg_match(
'!^[-+]\d{1,16}-(0\d|1[012])-([012]\d|3[01])T([01]\d|2[0123]):[0-5]\d:([0-5]\d|6[012])Z$!',
$time ) ) {
+ throw new InvalidArgumentException( '$time needs to be
a valid ISO 8601 date.' );
+ }
+
if ( !is_integer( $timezone ) ) {
throw new InvalidArgumentException( '$timezone needs to
be an integer' );
}
diff --git a/DataValues/tests/phpunit/includes/values/TimeValueTest.php
b/DataValues/tests/phpunit/includes/values/TimeValueTest.php
index 4ec1a77..279a974 100644
--- a/DataValues/tests/phpunit/includes/values/TimeValueTest.php
+++ b/DataValues/tests/phpunit/includes/values/TimeValueTest.php
@@ -166,6 +166,26 @@
'http://nyan.cat/original.php',
);
+ $argLists[] = array(
+ 'InvalidArgumentException',
+ '+0000000 2013-01-01T00:00:00Z',
+ 0,
+ 0,
+ 0,
+ TimeValue::PRECISION_SECOND,
+ 'http://nyan.cat/original.php',
+ );
+
+ $argLists[] = array(
+ 'InvalidArgumentException',
+ '+00000002013-01-01 T00:00:00Z',
+ 0,
+ 0,
+ 0,
+ TimeValue::PRECISION_SECOND,
+ 'http://nyan.cat/original.php',
+ );
+
return $argLists;
}
--
To view, visit https://gerrit.wikimedia.org/r/67962
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6990983ef0c0cad7c9d4f271bdf803902b94230b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: mw1.22-wmf6
Gerrit-Owner: Daniel Kinzler <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits