FoOlRulez/FoOlFuuka — Issue #40: Base64 for image search isn't URL safe
Author: Ekss
Created: 2012-01-15 00:16:45+00:00
State: open

Using base64 directly in URLs for image search can lead For example, the following URL:

http://archive.foolz.us/jp/image/fxjuK05J1URRPeb%2FIcEyyw/

The ``%2F`` is an URL encoded ``/``. When pasted into stuff like email clients or web forums, it can silently get turned back into ``/``, which will break the URL. FoOlFuuka itself does this transformation, too. I tried posting the above URL on [this post here](http://archive.foolz.us/jp/thread/8412183/#8412559_2) and the result is a broken link.

To avoid this, Fuuka used the module [Mime::Base64::URLSafe](http://search.cpan.org/~kazuho/MIME-Base64-URLSafe-0.01/lib/MIME/Base64/URLSafe.pm), which behaves in the same way as Python's ``base64.urlsafe_b64encode()``. It's actually really simple to implement by yourself, though. It's just a matter of stripping ``=``s (you already seem to do this), and turning ``+``s into ``-``s and ``/``s into ``_``s.

Those two character replacements should make sure you don't have any unexpected problems with breaking URLs.