com php-src: Fixed bug #69374 IntlDateFormatter formatObject returns wrong utf8 value: ext/intl/dateformat/dateformat_format_object. cpp
ext/intl/tests/bug69374.phpt
| From: | Anatol Belski | Date: | Thu, 02 Jun 2016 20:27:48 +0000 |
| Subject: | com php-src: Fixed bug #69374 IntlDateFormatter formatObject returns wrong utf8 value: ext/intl/dateformat/dateformat_format_object. cpp ext/intl/tests/bug69374.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-92285@lists.php.net to get a copy of this message | ||
Commit: 527ddacd2084d5112ba849d55ed8532d133cbd97
Author: Mic <lenhatanh86@gmail.com> Thu, 2 Jun 2016 22:27:48 +0200
Committer: Anatol Belski <ab@php.net> Thu, 2 Jun 2016 22:27:48 +0200
Parents: 4b2fb0b4aecfb33a0f33d09af77527652e7fc43b
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=527ddacd2084d5112ba849d55ed8532d133cbd97
Log:
Fixed bug #69374 IntlDateFormatter formatObject returns wrong utf8 value
Relying on invariant strings is a mistake. Not only UTF-8, but also
many charsets are not single byte. Actual date formats can be mixed
with arbitrary strings, and this can bring erroneous results in the
out. Thus, instead it is more convenient to say, that a format string
can consist either on UTF-8 or on pure ASCII as its subset.. This is
what is currently being done in other classes like Formatter, etc.
as well.
Bugs:
https://bugs.php.net/69374
Changed paths:
M ext/intl/dateformat/dateformat_format_object.cpp
A ext/intl/tests/bug69374.phpt
Diff:
diff --git a/ext/intl/dateformat/dateformat_format_object.cpp
b/ext/intl/dateformat/dateformat_format_object.cpp
index 3be7633..accb27e 100644
--- a/ext/intl/dateformat/dateformat_format_object.cpp
+++ b/ext/intl/dateformat/dateformat_format_object.cpp
@@ -188,11 +188,11 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object)
}
if (pattern) {
- df = new SimpleDateFormat(
- UnicodeString(Z_STRVAL_P(format), Z_STRLEN_P(format),
- UnicodeString::kInvariant),
- Locale::createFromName(locale_str),
- status);
+ StringPiece sp(Z_STRVAL_P(format));
+ df = new SimpleDateFormat(
+ UnicodeString::fromUTF8(sp),
+ Locale::createFromName(locale_str),
+ status);
if (U_FAILURE(status)) {
intl_error_set(NULL, status,
diff --git a/ext/intl/tests/bug69374.phpt b/ext/intl/tests/bug69374.phpt
new file mode 100644
index 0000000..4d9fffa
--- /dev/null
+++ b/ext/intl/tests/bug69374.phpt
@@ -0,0 +1,24 @@
+--TEST--
+IntlDateFormatter::formatObject(): returns wrong utf8 value when $format param is utf8 string
pattern.
+--SKIPIF--
+<?php
+if (!extension_loaded('intl')) die('skip intl extension not enabled'); ?>
+<?php if (version_compare(INTL_ICU_VERSION, '50.1.2') < 0) die('skip for ICU
>= 51.1.2'); ?>
+--FILE--
+<?php
+$millitimestamp = 1428133423941.0; // 14:43:43 April 04 2015
+$pattern1 = '\'tháng\' MM, y'; // yMM format for Vietnamese
+$pattern2 = 'y년 MMM'; // yMM format for Korean
+$date = IntlCalendar::createInstance('Asia/Ho_Chi_Minh');
+$date->setTime($millitimestamp);
+echo IntlDateFormatter::formatObject($date, $pattern1, 'vi_VN'), "\n";
+echo IntlDateFormatter::formatObject ($date, $pattern2, 'ko_KR'), "\n";
+?>
+==DONE==
+
+--EXPECTF--
+tháng 04, 2015
+2015년 4월
+==DONE==
+
+