|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-11-07 10:28 UTC] vrana@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 08 11:00:02 2026 UTC |
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)