Bug #64131 [Opn->Nab]: rawurlencode appends char in conj.w. base64_decode when url-len isn't div. by 3
| From: | cataphract@php.net | Date: | Sat, 02 Feb 2013 12:52:02 +0000 |
| Subject: | Bug #64131 [Opn->Nab]: rawurlencode appends char in conj.w. base64_decode when url-len isn't div. by 3 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-176400@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64131&edit=1
ID: 64131
Updated by: cataphract@php.net
Reported by: post at kira-bianca dot eu
Summary: rawurlencode appends char in conj.w. base64_decode
when url-len isn't div. by 3
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Linux
PHP Version: 5.4.11
Block user comment: N
Private report: N
New Comment:
you should be decoding with
base64_decode(rawurldecode($url_e))
that is, you should apply the functions in the reverse order.
See http://en.wikipedia.org/wiki/Inverse_function#Symmetry
Previous Comments:
------------------------------------------------------------------------
[2013-02-02 11:18:08] post at kira-bianca dot eu
Description:
------------
If I encode a URL with first the function base64_encode() and then with rawurlencode() are appended
in the URL may 1 or 2 characters "%3D".
If the length of the URL is divisible by 3, the result is okay.
If the division of the URL length by 3 a remainder of 1, to the url "%3D%3D" attached
With a remainder of 2, "%3D" attached.
Test script:
---------------
$dom = "domain";
for ($i=0; $i<10; $dom.='x', $i++){
$url = "$dom.ldk";
$url_e = rawurlencode(base64_encode("$url"));
printf("%20s (len div 3 = %1d); encoded:%32s; decoded:%s\n",
$url,
strlen($url)%3,
$url_e,
rawurldecode(base64_decode($url_e)));
}
Expected result:
----------------
domain.ldk (len div 3 = 1); encoded: ZG9tYWluLmxkaw%3D%3D;
decoded:domain.ldk\nÃÃ
domainx.ldk (len div 3 = 2); encoded: ZG9tYWlueC5sZGs%3D; decoded:domainx.ldk7
domainxx.ldk (len div 3 = 0); encoded: ZG9tYWlueHgubGRr; decoded:domainxx.ldk
domainxxx.ldk (len div 3 = 1); encoded: ZG9tYWlueHh4Lmxkaw%3D%3D;
decoded:domainxxx.ldk\nÃÃ
domainxxxx.ldk (len div 3 = 2); encoded: ZG9tYWlueHh4eC5sZGs%3D;
decoded:domainxxxx.ldk7
domainxxxxx.ldk (len div 3 = 0); encoded: ZG9tYWlueHh4eHgubGRr;
decoded:domainxxxxx.ldk
domainxxxxxx.ldk (len div 3 = 1); encoded: ZG9tYWlueHh4eHh4Lmxkaw%3D%3D;
decoded:domainxxxxxx.ldk\nÃÃ
domainxxxxxxx.ldk (len div 3 = 2); encoded: ZG9tYWlueHh4eHh4eC5sZGs%3D;
decoded:domainxxxxxxx.ldk7
domainxxxxxxxx.ldk (len div 3 = 0); encoded: ZG9tYWlueHh4eHh4eHgubGRr;
decoded:domainxxxxxxxx.ldk
domainxxxxxxxxx.ldk (len div 3 = 1); encoded:ZG9tYWlueHh4eHh4eHh4Lmxkaw%3D%3D;
decoded:domainxxxxxxxxx.ldk\nÃÃ
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64131&edit=1