From: Mic Date: Thu, 2 Jun 2016 20:27:48 +0000 (+0200) Subject: Fixed bug #69374 IntlDateFormatter formatObject returns wrong utf8 value X-Git-Tag: php-7.1.0alpha1~37 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=527ddacd2084d5112ba849d55ed8532d133cbd97;p=php 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. --- diff --git a/ext/intl/dateformat/dateformat_format_object.cpp b/ext/intl/dateformat/dateformat_format_object.cpp index 3be76332a8..accb27e63d 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 0000000000..4d9fffab7a --- /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-- + += 51.1.2'); ?> +--FILE-- +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== + +