Commit: 5324416b6514b6de53e7de269bc18b5807701051 Author: Anatol Belski <a...@php.net> Wed, 3 Jul 2013 11:12:46 +0200 Parents: b52fea6f3595d630541253f675c16a5db55eb8d0 Branches: PHP-5.5 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5324416b6514b6de53e7de269bc18b5807701051 Log: Fixed bug #65184 strftime() returns insufficient-length string under multibyte locales The msdn doc states 'strftime returns the number of characters', but prior to VS2012 it seems to have returned the number of bytes. Locale independent. The return is however \0-terminated, so strlen is just fine. The behaivor seems to be persisting in the later VC++ versions as the corresponding MSDN ticket is closed 'by design'. See http://connect.microsoft.com/VisualStudio/feedback/details/766205/vs2012-strftime-has-incorrect-return-value-in-vc-11-with-multibyte-codepages#details Bugs: https://bugs.php.net/65184 Changed paths: M NEWS M ext/date/php_date.c A ext/date/tests/bug65184.phpt Diff: diff --git a/NEWS b/NEWS index d59945f..9a78409 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,10 @@ PHP NEWS . Fixed bug #65066 (Cli server not responsive when responding with 422 http status code). (Adam) +- DateTime + . Fixed fug #65184 (strftime() returns insufficient-length string under + multibyte locales). (Anatol) + - GD . Fixed #65070 (bgcolor does not use the same format as the input image with imagerotate). (Pierre) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 28ac86b..0f8822a 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1678,6 +1678,13 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) break; } } +#if defined(PHP_WIN32) && _MSC_VER >= 1700 + /* VS2012 strftime() returns number of characters, not bytes. + See VC++11 bug id 766205. */ + if (real_len > 0) { + real_len = strlen(buf); + } +#endif timelib_time_dtor(ts); if (!gmt) { diff --git a/ext/date/tests/bug65184.phpt b/ext/date/tests/bug65184.phpt new file mode 100644 index 0000000..ade020c --- /dev/null +++ b/ext/date/tests/bug65184.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test bug #65184 strftime() returns insufficient-length string under multibyte locales +--SKIPIF-- +<?php +if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') { + die("skip Test is valid for Windows"); +} +?> +--FILE-- +<?php + setlocale(LC_ALL, 'Japanese_Japan.932'); + $s = strftime('%A'); + + for ($i = 0; $i < strlen($s); $i++) { + printf("%x ", ord($s[$i])); + } + echo "\n"; +?> +===DONE=== +--EXPECT-- +90 85 97 6a 93 fa +===DONE=== -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php