]> granicus.if.org Git - php/commitdiff
Fixed bug #75378 ([REGRESSION] IntlDateFormatter::parse() does not change $position...
authorXinchen Hui <laruence@gmail.com>
Mon, 16 Oct 2017 11:07:34 +0000 (19:07 +0800)
committerXinchen Hui <laruence@gmail.com>
Mon, 16 Oct 2017 11:07:34 +0000 (19:07 +0800)
NEWS
ext/intl/dateformat/dateformat_parse.c
ext/intl/tests/bug75378.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 0fcb02c235672fdd94527e57ba10e72923c573be..ced00b59467cd52a85f9051b62fda46cfa6f2f8d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,10 @@ PHP                                                                        NEWS
 - Fileinfo:
   . Upgrade bundled libmagic to 5.31. (Anatol)
 
+- Intl:
+  . Fixed bug #75378 ([REGRESSION] IntlDateFormatter::parse() does not change
+    $position argument). (Laruence)
+
 - JSON:
   . Fixed bug #68567 (JSON_PARTIAL_OUTPUT_ON_ERROR can result in JSON with null
     key). (Jakub Zelenka)
index 0e2290ffa171b4f8fbd958ddd63cadc0d16fa21f..bdf9a1e32ce0b2f6e38cd6fb95a597b647511b23 100644 (file)
@@ -145,6 +145,7 @@ PHP_FUNCTION(datefmt_parse)
        DATE_FORMAT_METHOD_FETCH_OBJECT;
 
        if (z_parse_pos) {
+               ZVAL_DEREF(z_parse_pos);
                convert_to_long(z_parse_pos);
                if (ZEND_LONG_INT_OVFL(Z_LVAL_P(z_parse_pos))) {
                        intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR);
@@ -188,6 +189,7 @@ PHP_FUNCTION(datefmt_localtime)
        DATE_FORMAT_METHOD_FETCH_OBJECT;
 
        if (z_parse_pos) {
+               ZVAL_DEREF(z_parse_pos);
                convert_to_long(z_parse_pos);
                if (ZEND_LONG_INT_OVFL(Z_LVAL_P(z_parse_pos))) {
                        intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR);
diff --git a/ext/intl/tests/bug75378.phpt b/ext/intl/tests/bug75378.phpt
new file mode 100644 (file)
index 0000000..c79e7f6
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+Bug #75378 ([REGRESSION] IntlDateFormatter::parse() does not change $position argument)
+--SKIPIF--
+<?php
+if (!extension_loaded('intl')) die('skip this test requires ext/intl');
+?>
+--FILE--
+<?php
+
+$formatter = new IntlDateFormatter("en-GB", IntlDateFormatter::NONE, IntlDateFormatter::NONE, 'UTC', null, 'yyyy-MM-dd');
+$position = 0;
+$parsedDate = $formatter->parse("2017-10-12", $position);
+var_dump($parsedDate, $position);
+$localdate = $formatter->localtime("2017-10-12", $position1);
+var_dump($localdate, $position1);
+?>
+--EXPECT--
+int(1507766400)
+int(10)
+array(9) {
+  ["tm_sec"]=>
+  int(0)
+  ["tm_min"]=>
+  int(0)
+  ["tm_hour"]=>
+  int(0)
+  ["tm_year"]=>
+  int(117)
+  ["tm_mday"]=>
+  int(12)
+  ["tm_wday"]=>
+  int(4)
+  ["tm_yday"]=>
+  int(285)
+  ["tm_mon"]=>
+  int(9)
+  ["tm_isdst"]=>
+  int(0)
+}
+int(10)