]> granicus.if.org Git - php/commitdiff
Fixed bug #65184 strftime() returns insufficient-length
authorAnatol Belski <ab@php.net>
Wed, 3 Jul 2013 09:12:46 +0000 (11:12 +0200)
committerAnatol Belski <ab@php.net>
Wed, 3 Jul 2013 09:12:46 +0000 (11:12 +0200)
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

NEWS
ext/date/php_date.c
ext/date/tests/bug65184.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index d59945f338c1faab5a44361a7d41fc7eddb2a770..9a78409726076426730c30ce5522d02e595b6390 100644 (file)
--- 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)
index 28ac86b119170b770f80554e93ce240376381b93..0f8822a90600620d8ffa0577ebac565a1a5712f7 100644 (file)
@@ -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 (file)
index 0000000..ade020c
--- /dev/null
@@ -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===