com php-src: Fixed bug #71516 IntlDateFormatter losts locale if pattern is set via constructor: ext/intl/dateformat/dateformat_create. cpp
ext/intl/tests/dateformat_bug71516.phpt
| From: | Anatol Belski | Date: | Fri, 08 Apr 2016 06:59:43 +0000 |
| Subject: | com php-src: Fixed bug #71516 IntlDateFormatter losts locale if pattern is set via constructor: ext/intl/dateformat/dateformat_create. cpp ext/intl/tests/dateformat_bug71516.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-91654@lists.php.net to get a copy of this message | ||
Commit: 49d31fa01d1cfe4515bd6f1cdb256374701a4489
Author: Anatol Belski <ab@php.net> Fri, 8 Apr 2016 08:59:06 +0200
Parents: d242a8fb68ce357d579c0bfc91c6b645fff87c04
Branches: PHP-7.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=49d31fa01d1cfe4515bd6f1cdb256374701a4489
Log:
Fixed bug #71516 IntlDateFormatter losts locale if pattern is set via constructor
Bugs:
https://bugs.php.net/71516
Changed paths:
M ext/intl/dateformat/dateformat_create.cpp
A ext/intl/tests/dateformat_bug71516.phpt
Diff:
diff --git a/ext/intl/dateformat/dateformat_create.cpp b/ext/intl/dateformat/dateformat_create.cpp
index 1999b6a..e90ad74 100644
--- a/ext/intl/dateformat/dateformat_create.cpp
+++ b/ext/intl/dateformat/dateformat_create.cpp
@@ -36,6 +36,7 @@ extern "C" {
#include "dateformat_helpers.h"
#include "zend_exceptions.h"
+
/* {{{ */
static int datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
{
@@ -117,14 +118,16 @@ static int datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool
is_constructor)
}
}
+ DATE_FORMAT_OBJECT(dfo) = udat_open((UDateFormatStyle)time_type,
+ (UDateFormatStyle)date_type, locale_str, NULL, 0, svalue,
+ slength, &INTL_DATA_ERROR_CODE(dfo));
+
if (pattern_str && pattern_str_len > 0) {
- DATE_FORMAT_OBJECT(dfo) = udat_open(UDAT_IGNORE, UDAT_IGNORE,
- locale_str, NULL, 0, svalue, slength,
- &INTL_DATA_ERROR_CODE(dfo));
- } else {
- DATE_FORMAT_OBJECT(dfo) = udat_open((UDateFormatStyle)time_type,
- (UDateFormatStyle)date_type, locale_str, NULL, 0, svalue,
- slength, &INTL_DATA_ERROR_CODE(dfo));
+ udat_applyPattern(DATE_FORMAT_OBJECT(dfo), true, svalue, slength);
+ if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) {
+ intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: error applying
pattern", 0);
+ goto error;
+ }
}
if (!U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) {
diff --git a/ext/intl/tests/dateformat_bug71516.phpt b/ext/intl/tests/dateformat_bug71516.phpt
new file mode 100644
index 0000000..88ba9bf
--- /dev/null
+++ b/ext/intl/tests/dateformat_bug71516.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Bug #71516 IntlDateFormatter losts locale if pattern is set via constructor
+--SKIPIF--
+<?php
+if (!extension_loaded('intl')) die('skip intl extension not enabled'); ?>
+--FILE--
+<?php
+
+$loc = "ru_RU";
+$goodFormatter = new IntlDateFormatter($loc, IntlDateFormatter::FULL, IntlDateFormatter::FULL, new
DateTimeZone("UTC"));
+$badFormatter = new IntlDateFormatter($loc, IntlDateFormatter::FULL, IntlDateFormatter::FULL, new
DateTimeZone("UTC"), null, "d MMM");
+$badFormatter2 = new IntlDateFormatter($loc, IntlDateFormatter::FULL, IntlDateFormatter::FULL, new
DateTimeZone("UTC"));
+$badFormatter2->setPattern("d MMM");
+
+echo "Formatter without pattern: " . $goodFormatter->getLocale() . PHP_EOL;
+echo "Formatter with pattern: " . $badFormatter->getLocale() . PHP_EOL;
+echo "Formatter with pattern set later: " . $badFormatter2->getLocale() . PHP_EOL;
+
+?>
+==DONE==
+--EXPECT--
+Formatter without pattern: ru
+Formatter with pattern: ru
+Formatter with pattern set later: ru
+==DONE==