-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
Labels
Comments
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 |
Comment 2 by sam.nguyen@sendgrid.com: Attached is an updated net/textproto/writer_test.go that covers this case Attachments:
|
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. |
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. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by sam.nguyen@sendgrid.com:
The text was updated successfully, but these errors were encountered: