Bug #66826 [Ana->Asn]: date() stopped accepting "\0" as a valid format value
Edit report at https://bugs.php.net/bug.php?id=66826&edit=1
ID: 66826
Updated by: kalle@php.net
Reported by: butkus dot justas at gmail dot com
Summary: date() stopped accepting "\0" as a valid format
value
-Status: Analyzed
+Status: Assigned
Type: Bug
Package: Date/time related
Operating System: Linux
PHP Version: 5.5.9
Assigned To: derick
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2015-08-18 17:24:56] cmb@php.net
As <https://3v4l.org/1vQ94> shows, this issue is fixed as
of PHP
7.0.0alpha1. Furthermore, the behavior until PHP 5.2.1 was not
really correct, because the null byte in the format string was
simply skipped (compare the string lengths).
To fix the issue for PHP 5.6, RETURN_STRINGL() instead of
RETURN_STRING would have to be used[1], but the actual length of
the string is only known inside of date_format, so this would
require some changes. I'm not sure if that's worth the trouble,
considering that the PHP 7 behavior is already correct, and that
a null byte in a format string is probably rather uncommon.
[1] <https://github.com/php/php-src/blob/php-5.6.12/ext/date/php_date.c#L3084>
------------------------------------------------------------------------
[2014-03-05 14:21:57] butkus dot justas at gmail dot com
Description:
------------
This might be either string handling related, or date-specific string handling related, but starting
with PHP 5.2.1 and still occurring in PHP 5.6.0alpha2, date() (as well as DateTime::format()) does
not accept "\0" (NUL) as valid formatting character as valid and truncates at that point.
Likely it means that at some point date() started treating $format value as null-terminated string.
Before PHP 5.2.1 the NUL byte was preserved in formatting output.
Reason behind using such characters: to have some clear and easily distinguishable separator which
doesn't take up visual space in output.
Test script:
---------------
<?php
date_default_timezone_set( 'UTC' );
$time = strtotime( '2014-01-31' );
$format = "\\Fm\0 j, Y";
var_dump( date( $format, $time ) );
$datetime = new DateTime( '@' . $time );
var_dump( $datetime->format( $format ) );
Expected result:
----------------
string(12) "F01 31, 2014"
string(12) "F01 31, 2014"
Actual result:
--------------
string(3) "F01"
string(3) "F01"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66826&edit=1
Thread (4 messages)