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: binascii.b2a_base64() trailing newline
Type: Stage:
Components: Extension Modules Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: fdrake Nosy List: barry, fdrake, gvanrossum
Priority: normal Keywords:

Created on 2001-09-20 20:36 by barry, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
patch-1.txt barry, 2001-09-20 20:36
Messages (7)
msg6603 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2001-09-20 20:36
binascii.b2a_base64() should not append a "courtesy
newline".  See attached patch (but the test suite
should be updated too).
msg6604 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2001-09-21 16:06
Logged In: YES 
user_id=6380

But won't this break working code?  I believe the courtesy
newline is documented. If people program around this
naively, their code will break.
msg6605 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2001-09-22 03:38
Logged In: YES 
user_id=12800

You're right, the newline is documented in b2a_base64().  I
actually hit this problem through the base64 module, which
uses binascii underneath.  The extra newline is implied in
the example, but not really documented.  I think it may also
be a bit misleading to quote RFC 1521 where that RFC does
not (I think) require the newline.

Two options:

- reassign to Fred for updating the base64 documentation
about the extra newline.

- get rid of the extra newline in base64 only, not in
binascii.  This can be accomplished by looking at the source
string: if it has a trailing newline, leave one in, if it
doesn't strip the extra newline from the result string. 
That's the solution I'll use in the email package if we
don't change base64.
msg6606 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2001-09-22 17:46
Logged In: YES 
user_id=6380

Whether or not it's documented for base64, changing that
will also break existing code.

It's a documentation issue (unfortunately).
msg6607 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2001-09-23 21:57
Logged In: YES 
user_id=3066

What in the base64 module needs to have documentation
corrected?  It sounds like the encode() and encodestring()
functions should be documented as generating a trailing
newline; is this correct?

Set status to pending.  Barry, when you respond to this
request for information the issue will be re-opened and
assigned to me.
msg6608 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2001-09-28 04:48
Logged In: YES 
user_id=12800

Correct.  base64.encode() and base64.encodestring() should
be documented as adding a trailing newline, but only if the
source string doesn't already end in a newline (i.e:

base64.encodestring('hello') == base64.encodestring('hello\n')
msg6609 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2001-09-28 16:02
Logged In: YES 
user_id=3066

Fixed in Doc/lib/libbase64.tex revision 1.19.
History
Date User Action Args
2022-04-10 16:04:27adminsetgithub: 35210
2001-09-20 20:36:11barrycreate