This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: base64.urlsafe_b64encode() shouldn't use the = character
Type: enhancement Stage: patch review
Components: Documentation Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: ajaksu2, georg.brandl, ryanbarrett
Priority: normal Keywords:

Created on 2007-02-16 03:11 by ryanbarrett, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg31277 - (view) Author: Ryan Barrett (ryanbarrett) Date: 2007-02-16 03:11
base64.urlsafe_b64encode() almost always returns strings that include the = character. this may be ok before the ? in a URL, but it's not OK after.

it would be nice if it substituted another character for =, like it does for + and /. if this is intentional, though, and you don't want to substitute for =, the documentation should probably be changed to note that it's only safe for use before the ?. (it doesn't include that caveat now.)

http://docs.python.org/lib/module-base64.html#l2h-1592
msg31278 - (view) Author: Ryan Barrett (ryanbarrett) Date: 2007-02-16 18:10
after more investigation, RFC3548 does say to use the = character for padding even in the URL-safe alphabet. weird.

so, it looks like the base64 module is just following the spec, and it's the spec that (seems) broken. sigh.

i'm off to try to figure out why RFC3548 says = is ok in URLs...
msg31279 - (view) Author: Ryan Barrett (ryanbarrett) Date: 2007-02-17 07:32
i talked to harald alvestrand, and he made the good point that the = character is only problematic in URL parameter names. it's ok, if unusual, in parameter values, since the & character is used at the end the value.

apart from that, though, he didn't sound like this would be a priority for the IETF to address. unfortunate, but understandable. :P

so, the resolution here might just be to update the base64 documentation to say that urlsafe_b64encode's output may include the = character. another option would be to change the code to use different character for padding, which would be nicer, but wouldn't follow the spec. up to you.
msg81706 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-02-12 02:14
Not following the spec doesn't seem reasonable. Adding a caveat about
how we follow the spec doesn't make much sense (I started to write one
and dropped it at "The resulting string" :D).
msg81906 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-02-13 10:57
Added a short note in r69576.
History
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44587
2009-02-13 10:57:04georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg81906
2009-02-12 02:14:24ajaksu2setnosy: + ajaksu2
messages: + msg81706
stage: patch review
2009-02-10 18:10:28ajaksu2setassignee: georg.brandl
type: enhancement
components: + Documentation, - Library (Lib)
nosy: + georg.brandl
2007-02-16 03:11:22ryanbarrettcreate