Bug #63738 [Asn->Csd]: unpack: back result with Z format
Edit report at https://bugs.php.net/bug.php?id=63738&edit=1
ID: 63738
Updated by: remi@php.net
Reported by: remi@php.net
Summary: unpack: back result with Z format
-Status: Assigned
+Status: Closed
Type: Bug
Package: Strings related
Operating System: GNU/Linux (Fedora 17)
PHP Version: 5.5Git-2012-12-11 (snap)
Assigned To: remi
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of remi
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4d8d5d83fce83c32a04cd8d8cf50d909ab101f38
Log: Fixed Bug #63738 unpack: back result with Z format
Previous Comments:
------------------------------------------------------------------------
[2012-12-11 14:15:38] remi@php.net
There still a problem with new 'z' format:
php -r '$a="\x00\x00\x00\x00"; var_dump($a); var_dump(unpack("Z4foo",
$a));'
Actual result:
string(4) "^@^@^@^@"
array(1) {
["foo"]=>
string(1) "^@"
}
When we expect:
string(4) "^@^@^@^@"
array(1) {
["foo"]=>
string(0) ""
}
------------------------------------------------------------------------
[2012-12-11 13:58:02] aharvey@php.net
Snap. :)
------------------------------------------------------------------------
[2012-12-11 13:57:35] aharvey@php.net
This was intentional â specifically, it was to fix bug #61038. Copy-pasting from the migration
guide (http://php.net/manual/en/migration55.changed-functions.php):
"unpack()'s a format no longer strips trailing null bytes, bringing it into line with
Perl's behaviour."
------------------------------------------------------------------------
[2012-12-11 13:57:30] remi@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Sorry, haven't read carefully UPGRADING
- pack()/unpack() had the following changes, which bring it more in line
with Perl's behavior:
- Implemented format character "Z": NUL-padded string
- "a" now does not remove trailing NUL characters on unpack() anymore
- "A" will now strip all trailing ASCII whitespace on unpack() (it used to
remove only trailing spaces).
------------------------------------------------------------------------
[2012-12-11 13:51:09] remi@php.net
Description:
------------
Seems a regression between 5.4.9 and 5.5.0-dev
This breaks Archive_Tar
Test script:
---------------
<?php
$a="AB\x00\x00";
var_dump($a);
var_dump(unpack("a4foo", $a));
Expected result:
----------------
With php 5.4.9:
string(4) "AB^@^@"
array(1) {
["foo"]=>
string(2) "AB"
}
Actual result:
--------------
With php 5.5.0-dev:
string(4) "AB^@^@"
array(1) {
["foo"]=>
string(4) "AB^@^@"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63738&edit=1
Thread (7 messages)