#44583 [Opn->Csd]: base64_decode: innaccurate documentation for $strict argument
| From: | vrana@php.net | Date: | Fri, 07 Nov 2008 10:28:54 +0000 |
| Subject: | #44583 [Opn->Csd]: base64_decode: innaccurate documentation for $strict argument | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-1412@lists.php.net to get a copy of this message | ||
ID: 44583
Updated by: vrana@php.net
Reported By: robin_fernandes at uk dot ibm dot com
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: Windows
PHP Version: Irrelevant
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
"Returns FALSE if input contains character from outside the base64
alphabet."
Previous Comments:
------------------------------------------------------------------------
[2008-03-31 16:03:37] robin_fernandes at uk dot ibm dot com
Description:
------------
In the doc for base64_decode(), the description of the $strict
parameter reads:
"Returns FALSE if input contains space or some other separator."
In fact, the return value of base64_decode() is not affected by spaces
or other white-space chars, regardless of the $strict flag. It is,
however, affected by other chars outside of the base64 alphabet. See
reproduce code.
The implementation in base64.c suggests this is intentional:
if ((!strict && ch < 0) || ch == -1) { /* a space or some other
separator character, we simply skip over */
continue;
}
A better description for the $strict param would be:
"When true, base64_decode() will return false if the data contains a
non-whitespace character outside of the base64 alphabet. When false, all
characters outside of the base64 alphabet are simply ignored."
FYI, here's what RFC 2045 (referred to in the doc) has to say about how
the decoder should deal with chars outside of the base64 alphabet:
"All line breaks or other characters not found in Table 1 must be
ignored by decoding software. In base64 data, characters other than
those in Table 1, line breaks, and other white space probably indicate a
transmission error, about which a warning message or even a message
rejection might be appropriate under some circumstances."
Reproduce code:
---------------
<?php
echo "Whitespace does not affect base64_decode, even with
\$strict===true:\n";
$noWhiteSpace = "aGVsbG8gd29ybGQh";
var_dump(base64_decode($noWhiteSpace, false));
var_dump(base64_decode($noWhiteSpace, true));
$withWhiteSpace = "a GVs bG8gd2
9ybGQh";
var_dump(base64_decode($withWhiteSpace, false));
var_dump(base64_decode($withWhiteSpace, true));
echo "\n\nOther chars outside the base64 alphabet are ignored when
\$strict===false, but cause failure with \$strict===true:\n";
$badChars = $noWhiteSpace . '*';
var_dump(base64_decode($badChars, false));
var_dump(base64_decode($badChars, true));
?>
Expected result:
----------------
n/a
Actual result:
--------------
Whitespace does not affect base64_decode, even with $strict===true:
string(12) "hello world!"
string(12) "hello world!"
string(12) "hello world!"
string(12) "hello world!"
Other chars outside the base64 alphabet are ignored when
$strict===false, but cause failure with $strict===true:
string(12) "hello world!"
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44583&edit=1