From 9c22046bffac523e1eff12d7eff7409c786de176 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 8 Aug 2013 16:52:11 +0200 Subject: [PATCH 1/4] Do not pass numeric strings to strtotime() when formatting dates. strtotime() will return false and the date will be formatted as the 0-timestamp (e.g. January 1, 1970 00:00) otherwise. --- lib/l10n.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/l10n.php b/lib/l10n.php index d2da302b64..5cfe119a4f 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -387,7 +387,7 @@ class OC_L10N { if($data instanceof DateTime) { return $data->format($this->localizations[$type]); } - elseif(is_string($data)) { + elseif(is_string($data) && !is_numeric($data)) { $data = strtotime($data); } $locales = array(self::findLanguage()); From 43be3eb4d0112215f03157c81f9f94e03009718f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 9 Aug 2013 01:21:45 +0200 Subject: [PATCH 2/4] Changing elseif statement to what the PEAR coding guidelines say. --- lib/l10n.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/l10n.php b/lib/l10n.php index 5cfe119a4f..f93443b886 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -386,8 +386,7 @@ class OC_L10N { case 'time': if($data instanceof DateTime) { return $data->format($this->localizations[$type]); - } - elseif(is_string($data) && !is_numeric($data)) { + } elseif(is_string($data) && !is_numeric($data)) { $data = strtotime($data); } $locales = array(self::findLanguage()); From b6b1bc5d09e1b4d4848ae99e0963217f92ad151c Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 9 Aug 2013 22:28:03 +0200 Subject: [PATCH 3/4] Add datetime test for numeric string. --- tests/lib/l10n.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/lib/l10n.php b/tests/lib/l10n.php index dfc5790c2e..bd5984add1 100644 --- a/tests/lib/l10n.php +++ b/tests/lib/l10n.php @@ -52,4 +52,11 @@ class Test_L10n extends PHPUnit_Framework_TestCase { $this->assertEquals('5 oken', (string)$l->n('%n window', '%n windows', 5)); } + /** + * Issue #4360: Do not call strtotime() on numeric strings. + */ + public function testNumericStringToDateTime() { + $l = new OC_L10N('test'); + $this->assertSame('February 13, 2009 23:31', $l->l('datetime', '1234567890')); + } } From 0e3dea7111e66c3619c6fe989e79ff80fb18e2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 9 Aug 2013 23:36:23 +0200 Subject: [PATCH 4/4] adding test case for a numeric value --- tests/lib/l10n.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/lib/l10n.php b/tests/lib/l10n.php index bd5984add1..12eac818f8 100644 --- a/tests/lib/l10n.php +++ b/tests/lib/l10n.php @@ -53,10 +53,15 @@ class Test_L10n extends PHPUnit_Framework_TestCase { } /** - * Issue #4360: Do not call strtotime() on numeric strings. - */ + * Issue #4360: Do not call strtotime() on numeric strings. + */ public function testNumericStringToDateTime() { $l = new OC_L10N('test'); $this->assertSame('February 13, 2009 23:31', $l->l('datetime', '1234567890')); } + + public function testNumericToDateTime() { + $l = new OC_L10N('test'); + $this->assertSame('February 13, 2009 23:31', $l->l('datetime', 1234567890)); + } }