OSDN Git Service

BugTrack/2414 strtotime return false on parsing failure in PHP5.1+
authorumorigu <umorigu@gmail.com>
Thu, 16 Feb 2017 15:09:23 +0000 (00:09 +0900)
committerumorigu <umorigu@gmail.com>
Thu, 16 Feb 2017 15:09:23 +0000 (00:09 +0900)
http://php.net/manual/en/function.strtotime.php
Returns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0,
this function would return -1 on failure.

plugin/calendar_viewer.inc.php
plugin/new.inc.php
plugin/showrss.inc.php

index cc4c978..3ecb385 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone
-// $Id: calendar_viewer.inc.php,v 1.37 2011/01/25 15:01:01 henoheno Exp $
-// Copyright (C) 2002-2005, 2007 PukiWiki Developers Team
+// calendar_viewer.inc.php
+// Copyright  2002-2017 PukiWiki Development Team
 // License: GPL v2 or (at your option) any later version
 //
 // Calendar viewer plugin - List pages that calendar/calnedar2 plugin created
@@ -177,7 +177,7 @@ function plugin_calendar_viewer_convert()
 
                if (PLUGIN_CALENDAR_VIEWER_DATE_FORMAT !== FALSE) {
                        $time = strtotime(basename($page)); // $date_sep must be assumed '-' or ''!
-                       if ($time == -1) {
+                       if ($time === FALSE || $time === -1) {
                                $s_page = htmlsc($page); // Failed. Why?
                        } else {
                                $week   = $weeklabels[date('w', $time)];
@@ -330,4 +330,3 @@ function plugin_calendar_viewer_isValidDate($aStr, $aSepList = '-/ .')
                return FALSE;
        }
 }
-
index a9306b6..5a41d0c 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: new.inc.php,v 1.10 2011/01/25 15:01:01 henoheno Exp $
+// new.inc.php
+// Copyright  2003-2017 PukiWiki Development Team
+// License: GPL v2 or (at your option) any later version
 //
 // New! plugin
 //
index bfa799b..2547748 100644 (file)
@@ -2,7 +2,7 @@
 // PukiWiki - Yet another WikiWikiWeb clone
 // showrss.inc.php
 // Copyright:
-//     2002-2016 PukiWiki Development Team
+//     2002-2017 PukiWiki Development Team
 //     2002      PANDA <panda@arino.jp>
 //     (Original)hiro_do3ob@yahoo.co.jp
 // License: GPL, same as PukiWiki
@@ -282,14 +282,17 @@ class ShowRSS_XML
                        
                } else if (isset($item['PUBDATE'])) {
                        $time = plugin_showrss_get_timestamp($item['PUBDATE']);
-                       
-               } else if (isset($item['DESCRIPTION']) &&
-                       ($description = trim($item['DESCRIPTION'])) != '' &&
-                       ($time = strtotime($description)) != -1) {
-                               $time -= LOCALZONE;
-
                } else {
-                       $time = time() - LOCALZONE;
+                       $time_from_desc = FALSE;
+                       if (isset($item['DESCRIPTION']) &&
+                               (($description = trim($item['DESCRIPTION'])) != '')) {
+                               $time_from_desc = strtotime($description);
+                       }
+                       if ($time_from_desc !== FALSE && $time_from_desc !== -1) {
+                               $time = $time_from_desc - LOCALZONE;
+                       } else {
+                               $time = time() - LOCALZONE;
+                       }
                }
                $item['_TIMESTAMP'] = $time;
                $date = get_date('Y-m-d', $item['_TIMESTAMP']);
@@ -314,7 +317,7 @@ function plugin_showrss_get_timestamp($str)
        $matches = array();
        if (preg_match('/(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2})(([+-])(\d{2}):(\d{2}))?/', $str, $matches)) {
                $time = strtotime($matches[1] . ' ' . $matches[2]);
-               if ($time == -1) {
+               if ($time === FALSE || $time === -1) {
                        $time = UTIME;
                } else if ($matches[3]) {
                        $diff = ($matches[5] * 60 + $matches[6]) * 60;
@@ -323,6 +326,6 @@ function plugin_showrss_get_timestamp($str)
                return $time;
        } else {
                $time = strtotime($str);
-               return ($time == -1) ? UTIME : $time - LOCALZONE;
+               return ($time === FALSE || $time === -1) ? UTIME : $time - LOCALZONE;
        }
 }