Last Updated: 2021-05-16
We had an unsubscribe link that was secured via a hashed
to the URL. This hash, unfortunately, sometimes contained slashes, and whenever
it did, the Laravel router got confused, thinking the user had requested a
different resource altogether (instead of the unsubscribe one). I tried calling
urlencode on the hash, but the problem persisted. Apparently the Laravel
router also cannot handle URL encoded hashes.
So I decided to encode it with
base64 instead. This character set should be
perfect for channels that are only reliable with text content (e.g. for HTTP),
right? So I thought. What you really want is
Normal base64 uses the following characters:
/(index 62 and 63)
=is used as padding
Of course, 3 characters,
=, are used in URLs. Therefore the urlsafe version of base64 needs some modifications:
+gets encoded as
/is encoded as
Another solution, that works, is to take the normal base64 string, and then
urlencode it using the standard tools, e.g. in Python / Ruby etc.
base64_urlsafeotherwise the weird characters will cause problems.