php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #33650 base64_encode alternate dictionary (RFC 3548)
Submitted: 2005-07-12 00:33 UTC Modified: 2015-01-08 23:41 UTC
Votes:6
Avg. Score:4.3 ± 0.7
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:1 (20.0%)
From: tiago dot freire at gmail dot com Assigned:
Status: Open Package: *URL Functions
PHP Version: * OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tiago dot freire at gmail dot com
New email:
PHP Version: OS:

 

 [2005-07-12 00:33 UTC] tiago dot freire at gmail dot com
Description:
------------
Per RFC 3548 (http://www.ietf.org/rfc/rfc3548.txt) , there is an alternate alphabet for base64 encoding and decoding,addressing the issue of unfriendliness of the '/' to filesystems and URLs.

<snip>

Table 2: The "URL and Filename safe" Base 64 Alphabet

    Value Encoding  Value Encoding  Value Encoding  Value Encoding
       0 A            17 R            34 i            51 z
       1 B            18 S            35 j            52 0
       2 C            19 T            36 k            53 1
       3 D            20 U            37 l            54 2
       4 E            21 V            38 m            55 3
       5 F            22 W            39 n            56 4
       6 G            23 X            40 o            57 5
       7 H            24 Y            41 p            58 6
       8 I            25 Z            42 q            59 7
       9 J            26 a            43 r            60 8
      10 K            27 b            44 s            61 9
      11 L            28 c            45 t            62 - (minus)
      12 M            29 d            46 u            63 _ (understrike)
      13 N            30 e            47 v
      14 O            31 f            48 w         (pad) =
      15 P            32 g            49 x
      16 Q            33 h            50 y

</snip>

As you can see, the only difference is that the last two characters (+ and /) are substituted by '-' (minus) and '_' (underscore). It should be trivial for base64_encode to have a flag so that the message can be encoded with the alternate  alphabet. since there is no clash between alphabet, olny the substitution of two characters for other chars which were not part of it, base64_decode should recognize both without the need of an additional parameter. My suggestion is to add an optional flag as a second parameter to tell base64_encode that it should use the URL-friendly encoding. Its absence will indicate the traditional behaviour.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-08 23:41 UTC] ajf@php.net
-Package: Feature/Change Request +Package: *URL Functions -Operating System: Linux +Operating System: Li* -PHP Version: 5.0.4 +PHP Version: *
 [2015-01-08 23:41 UTC] ajf@php.net
This would be a sensible addition.
 [2015-01-08 23:41 UTC] ajf@php.net
-Operating System: Li* +Operating System: *
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC