Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/textproto: DotWriter inserts extra newline #6743

Closed
gopherbot opened this issue Nov 9, 2013 · 9 comments
Closed

net/textproto: DotWriter inserts extra newline #6743

gopherbot opened this issue Nov 9, 2013 · 9 comments

Comments

@gopherbot
Copy link

by sam.nguyen@sendgrid.com:

What steps will reproduce the problem?
1. Encode a string with textproto.Writer
2. When it is decoded, it contains an additional newline

Reproduction
http://play.golang.org/p/CBnfXtHpF4

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
linux

Which version are you using?  (run 'go version')
1.2rc3
@gopherbot
Copy link
Author

Comment 1 by sam.nguyen@sendgrid.com:

Sorry, I think my original diagnosis was incorrect. It looks like textproto.DotWriter
removes a newline if the input ends in a newline. Here is a clearer reproduction:
http://play.golang.org/p/azGP9tlbWb

@gopherbot
Copy link
Author

Comment 2 by sam.nguyen@sendgrid.com:

Attached is an updated net/textproto/writer_test.go that covers this case

Attachments:

  1. writer_test.go (1022 bytes)

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 3:

Labels changed: added go1.3maybe.

@dsymonds
Copy link
Contributor

dsymonds commented Dec 2, 2013

Comment 4:

Labels changed: added priority-later, packagebug, removed priority-triage.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 5:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 6:

Labels changed: added repo-main.

@gopherbot
Copy link
Author

Comment 7 by walkeraj:

Isn't this behaving as intended?  All bare newlines are converted to \r\n and a '.\r\n'
is added at the end of the buffer when the writer is closed as per spec (see
http://tools.ietf.org/html/rfc5321#section-4.5.2).  The reason this might appear
inconsistent is that you're immediately calling Close(), which triggers the DotWriter to
wrap things up to ensure that the buffer ends with '\r\n.\r\n'
The reason \r\n is added to the end of "foo" is that, when Close() is called, the writer
is in the 'wstateData' state, meaning \r\n is necessary before the .\r\n closing line.
The reason \r\n is added at the end of "foo\n" is that newlines are prefixed with '\r'
when in the 'wstateData' state, which then sets the state to 'wstateBeginLine'.  When in
this state, Close() simply writes out the .\r\n closing line and flushes.  Either way,
this is exactly how you'd expect it to work.

@gopherbot
Copy link
Author

Comment 8 by sam.nguyen@sendgrid.com:

Thanks for the explanation. After further reading, yes it looks like you are correct
that this does what is indicated in the documentation:
"DotWriter returns a writer that can be used to write a dot-encoding to w. It takes care
of inserting leading dots when necessary, translating line-ending \n into \r\n, and
adding the final .\r\n line when the DotWriter is closed. The caller should close the
DotWriter before the next call to a method on w."
-- http://golang.org/pkg/net/textproto/#Writer.DotWriter
The specified behavior is not what I expected, but my expectations seem to be off-target.

@bradfitz
Copy link
Contributor

Comment 9:

Status changed to Retracted.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants