So recently I discovered that if I inclue ‘~’ in a user’s bios, I get a base64decode error from Discourse. It can handle all sorts of other problematic characters just fine (spaces, =, %, &) but not ~ for some reason.
Anyone else encounter this issue?
My first thought is that perhaps my encoding could be wrong, but I haven’t been able figure it out.
It propably should be fixed, but that question is above my paygrade and skills. But out of pure practical curiosity: why someone would use a tilde in a bio?
I run a multilingual forum and in other cultures ‘~’ is frequently used. As an example, in Korean, it’s often used at the end to soften your tone, like ‘If you have any questions, let me know~’
Is it? A bug is something that is done, but doesn’t work. This is more like question ”is it done or not” and then it’s more Feature if not a support question.
It looks like urlsafe_b64encode replaces some characters in the base64 encoding. From the docs:
Encode bytes-like objects using the URL- and filesystem-safe alphabet, which substitutes - instead of + and _ instead of / in the standard Base64 alphabet, and return the encoded bytes. The result can still contain = .
That means the result isn’t standard base64, and won’t be compatible with Discourse’s decoding.
I’d recommend using the normal b64encode function instead. Your HTTP library should take care of the URL escaping if needed.