Bug #67642 [NEW]: getallheaders does not clean array keys

From: Date: Thu, 17 Jul 2014 15:00:28 +0000
Subject: Bug #67642 [NEW]: getallheaders does not clean array keys
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186694@lists.php.net to get a copy of this message
From:             herve at moulticast dot net
Operating system: Linux Debian 3.14-1-amd64
PHP version:      5.6.0RC2
Package:          FPM related
Bug Type:         Bug
Bug description:getallheaders does not clean array keys

Description:
------------
Running Debian with kernel 3.14-1-amd64
Webserver: NginX 1.6.0
PHP: 5.6.0RC2 FPM
 
The getallheaders() method does not build a clean array.

When trying to access some values via $arr['key'] it doesn't work
because there is a non printable character '0' that is added at the end
of the key.


Test script:
---------------
<?php
        // Working example
        foreach($_SERVER as $key => $value) { 
                print('Key: '. $key . ' => ' . $value . "\n");
                $key_arr = str_split($key);
                foreach($key_arr as $char) {
                        print($char . ' => ' . ord($char) .' ');
                }
                print "\n";
        }

        // Buggy example using getallheaders
        $hdrs = getallheaders();
        foreach($hdrs as $key => $value) {
                print('Key: '. $key . ' => ' . $value . "\n");
                $key_arr = str_split($key);
                foreach($key_arr as $char) {
                        print($char . ' => ' . ord($char) .' ');
                }
                print "\n";
        }
?>

Expected result:
----------------
Key for header 'User-Agent' should be (in ASCII): 

85 115 101 114 45 65 103 101 110 116


Actual result:
--------------
Key for header 'User-Agent' is (in ASCII):

85 115 101 114 45 65 103 101 110 116 0

-- 
Edit bug report at https://bugs.php.net/bug.php?id=67642&edit=1
-- 



Thread (7 messages)

« previous php.bugs (#186694) next »