Req #33650 [Opn]: base64_encode alternate dictionary (RFC 3548)

From: Date: Thu, 08 Jan 2015 23:41:38 +0000
Subject: Req #33650 [Opn]: base64_encode alternate dictionary (RFC 3548)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189786@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=33650&edit=1

 ID:                 33650
 Updated by:         ajf@php.net
 Reported by:        tiago dot freire at gmail dot com
 Summary:            base64_encode alternate dictionary (RFC 3548)
 Status:             Open
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            *URL Functions
-Operating System:   Linux
+Operating System:   Li*
-PHP Version:        5.0.4
+PHP Version:        *
 Block user comment: N
 Private report:     N

 New Comment:

This would be a sensible addition.


Previous Comments:
------------------------------------------------------------------------
[2005-07-12 00:33:40] 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.



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



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


Thread (2 messages)

« previous php.bugs (#189786) next »