php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #80870
Patch base64_encode_testscript revision 2021-04-13 15:03 UTC by bugs at jth dot net
Patch base64_patch revision 2021-04-13 14:55 UTC by bugs at jth dot net

Patch base64_encode_testscript for Strings related Bug #80870

Patch version 2021-04-13 15:03 UTC

Return to Bug #80870 | Download this patch
Patch Revisions:

Developer: bugs@jth.net

--TEST--
Testing the ability of base64_decode of decoding streams of base64 encoded blocks
and ignoring missing or additional terminators at the end of an encoded block
when not in strict mode.
--FILE--
<?php
$ss = Array(
'Line nr 1 :TGluZSBuciAxIA==', 
'Line nr 1 :TGluZSBuciAxIA=',
'Line nr 1 :TGluZSBuciAxIA===',

'Line nr 2a :TGluZSBuciAyYSA=', 
'Line nr 2a :TGluZSBuciAyYSA',
'Line nr 2a :TGluZSBuciAyYSA==',

'Line nr 3ab :TGluZSBuciAzYWIg', 
'Line nr 3ab :TGluZSBuciAzYWIg=', 
'Line nr 3ab :TGluZSBuciAzYWIg==',

'Line nr 1 Line nr 2a Line nr 3ab :TGluZSBuciAxIA== 
TGluZSBuciAyYSA=
TGluZSBuciAzYWIg',
'Line nr 1 Line nr 2a Line nr 3ab :TGluZSBuciAxIA== TGluZSBuciAyYSA= TGluZSBuciAzYWIg',
'Line nr 1 Line nr 2a Line nr 3ab :TGluZSBuciAxIA== TGluZSBuciAyYSA== TGluZSBuciAzYWIg',
'Line nr 1 Line nr 2a Line nr 3ab :TGluZSBuciAxIA= TGluZSBuciAyYSA= TGluZSBuciAzYWIg',
'Line nr 1 Line nr 2a Line nr 3ab :TGluZSBuciAxIA== TGluZSBuciAyYSA= TGluZSBuciAzYWIg==',
);

/*
$s1 = base64_encode("Line nr 1 ");
$s2 = base64_encode("Line nr 2a ");
$s3 = base64_encode("Line nr 3ab ");
$str = $s1."\n".$s2."\n".$s3;
echo $str."\n";
TGluZSBuciAxIA==
TGluZSBuciAyYSA=
TGluZSBuciAzYWIg
*/

foreach ($ss as $s) {
list($so,$sc) = explode(':', $s);
echo "CODED=".$sc."\n";

$res = base64_decode($sc, FALSE);
if ($res === FALSE) {
 $res = "ERROR";
}
echo " UNCODED=$res\n";

$res = base64_decode($sc, TRUE);
if ($res === FALSE) {
 $res = "ERROR";
}
echo " UNCODEDSTRICT=$res\n";
}

?>
--EXPECT--
CODED=TGluZSBuciAxIA==
 UNCODED=Line nr 1 
 UNCODEDSTRICT=Line nr 1 
CODED=TGluZSBuciAxIA=
 UNCODED=Line nr 1 
 UNCODEDSTRICT=ERROR
CODED=TGluZSBuciAxIA===
 UNCODED=Line nr 1 
 UNCODEDSTRICT=ERROR
CODED=TGluZSBuciAyYSA=
 UNCODED=Line nr 2a 
 UNCODEDSTRICT=Line nr 2a 
CODED=TGluZSBuciAyYSA
 UNCODED=Line nr 2a 
 UNCODEDSTRICT=Line nr 2a 
CODED=TGluZSBuciAyYSA==
 UNCODED=Line nr 2a 
 UNCODEDSTRICT=ERROR
CODED=TGluZSBuciAzYWIg
 UNCODED=Line nr 3ab 
 UNCODEDSTRICT=Line nr 3ab 
CODED=TGluZSBuciAzYWIg=
 UNCODED=Line nr 3ab 
 UNCODEDSTRICT=ERROR
CODED=TGluZSBuciAzYWIg==
 UNCODED=Line nr 3ab 
 UNCODEDSTRICT=ERROR
CODED=TGluZSBuciAxIA== 
TGluZSBuciAyYSA=
TGluZSBuciAzYWIg
 UNCODED=Line nr 1 Line nr 2a Line nr 3ab 
 UNCODEDSTRICT=Line nr 1 Line nr 2a Line nr 3ab 
CODED=TGluZSBuciAxIA== TGluZSBuciAyYSA= TGluZSBuciAzYWIg
 UNCODED=Line nr 1 Line nr 2a Line nr 3ab 
 UNCODEDSTRICT=Line nr 1 Line nr 2a Line nr 3ab 
CODED=TGluZSBuciAxIA== TGluZSBuciAyYSA== TGluZSBuciAzYWIg
 UNCODED=Line nr 1 Line nr 2a Line nr 3ab 
 UNCODEDSTRICT=ERROR
CODED=TGluZSBuciAxIA= TGluZSBuciAyYSA= TGluZSBuciAzYWIg
 UNCODED=Line nr 1 Line nr 2a Line nr 3ab 
 UNCODEDSTRICT=ERROR
CODED=TGluZSBuciAxIA== TGluZSBuciAyYSA= TGluZSBuciAzYWIg==
 UNCODED=Line nr 1 Line nr 2a Line nr 3ab 
 UNCODEDSTRICT=ERROR
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 22:01:28 2024 UTC