Req #80870 [Com]: base64_decode: Support a "stream" of multiple encoded strings

From: Date: Sun, 06 Jun 2021 23:42:07 +0000
Subject: Req #80870 [Com]: base64_decode: Support a "stream" of multiple encoded strings
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234236@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80870&edit=1

 ID:                 80870
 Comment by:         a at b dot c dot de
 Reported by:        bugs at jth dot net
 Summary:            base64_decode: Support a "stream" of multiple
                     encoded strings
 Status:             Open
 Type:               Feature/Change Request
 Package:            Strings related
 Operating System:   Linux
 PHP Version:        7.4.16
 Block user comment: N
 Private report:     N

 New Comment:

So the job of could be done with a few lines of PHP code; if you want to play code golf you could
get it in under 100 characters, but for real-world usage a few lines would be better.


Previous Comments:
------------------------------------------------------------------------
[2021-06-05 19:07:16] bugs at jth dot net

No problem. One might add these test cases to the test script uploaded to check for this case.

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

CODED=TGluZSBuciAzYWIg TGluZSBuciAyYSA= TGluZSBuciAxIA==
 UNCODED=Line nr 3ab Line nr 2a Line nr 1
 UNCODEDSTRICT=Line nr 3ab Line nr 2a Line nr 1
CODED=TGluZSBuciAzYWIg TGluZSBuciAzYWIg TGluZSBuciAxIA==
 UNCODED=Line nr 3ab Line nr 3ab Line nr 1
 UNCODEDSTRICT=Line nr 3ab Line nr 3ab Line nr 1

------------------------------------------------------------------------
[2021-06-05 12:23:20] a at b dot c dot de

What if the first block isn't padded with '=' because the data it's encoding is
a multiple of three bytes in length?

$s1 = base64_encode("Line nr 1 bcdefgh\n");
$s2 = base64_encode("Line nr 2 \n");
$str = $s1."\n".$s2;
echo $str;
echo base64_decode($str);

------------------------------------------------------------------------
[2021-04-13 15:08:57] bugs at jth dot net

I just uploaded a patch as well as a test script (for 8.0.3)
There should be no change in the old behaviour for single base64 blocks.

------------------------------------------------------------------------
[2021-04-13 15:03:44] bugs at jth dot net

The following patch has been added/updated:

Patch Name: base64_encode_testscript
Revision:   1618326224
URL:        https://bugs.php.net/patch-display.php?bug=80870&patch=base64_encode_testscript&revision=1618326224

------------------------------------------------------------------------
[2021-04-13 14:55:38] bugs at jth dot net

The following patch has been added/updated:

Patch Name: base64_patch
Revision:   1618325738
URL:        https://bugs.php.net/patch-display.php?bug=80870&patch=base64_patch&revision=1618325738

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=80870


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


Thread (19 messages)

« previous php.bugs (#234236) next »