Skip to content

Commit

Permalink
Fix lint errors introduced by textproto import (#285)
Browse files Browse the repository at this point in the history
* textproto: Add comments to make go vet pass

* textproto: fix errcheck lint errors from imported files
  • Loading branch information
jhillyerd committed Mar 13, 2023
1 parent 340151c commit 67b5cbe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
10 changes: 5 additions & 5 deletions internal/textproto/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (r *Reader) skipSpace() int {
break
}
if c != ' ' && c != '\t' {
r.R.UnreadByte()
_ = r.R.UnreadByte()
break
}
n++
Expand Down Expand Up @@ -373,7 +373,7 @@ func (d *dotReader) Read(b []byte) (n int, err error) {
}
// Not part of .\r\n.
// Consume leading dot and emit saved \r.
br.UnreadByte()
_ = br.UnreadByte()
c = '\r'
d.state = stateData

Expand All @@ -383,7 +383,7 @@ func (d *dotReader) Read(b []byte) (n int, err error) {
break
}
// Not part of \r\n. Emit saved \r
br.UnreadByte()
_ = br.UnreadByte()
c = '\r'
d.state = stateData

Expand Down Expand Up @@ -418,7 +418,7 @@ func (r *Reader) closeDot() {
for r.dot != nil {
// When Read reaches EOF or an error,
// it will set r.dot == nil.
r.dot.Read(buf)
_, _ = r.dot.Read(buf)
}
}

Expand Down Expand Up @@ -589,7 +589,7 @@ var nl = []byte("\n")
// that will be in this header. If it gets confused, it returns 0.
func (r *Reader) upcomingHeaderNewlines() (n int) {
// Try to determine the 'hint' size.
r.R.Peek(1) // force a buffer load if empty
_, _ = r.R.Peek(1) // force a buffer load if empty
s := r.R.Buffered()
if s == 0 {
return
Expand Down
9 changes: 9 additions & 0 deletions internal/textproto/reader_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"math"
)

// ReadEmailMIMEHeader reads a MIME-style header from r.
//
// This is a modified version of the stock func that better handles the characters
// we must support in email, instead of just HTTP.
func (r *Reader) ReadEmailMIMEHeader() (MIMEHeader, error) {
return readEmailMIMEHeader(r, math.MaxInt64)
}
Expand Down Expand Up @@ -91,6 +95,11 @@ func readEmailMIMEHeader(r *Reader, lim int64) (MIMEHeader, error) {
}
}

// CanonicalEmailMIMEHeaderKey returns the canonical format of the
// MIME header key s.
//
// This is a modified version of the stock func that better handles the characters
// we must support in email, instead of just HTTP.
func CanonicalEmailMIMEHeaderKey(s string) string {
// Quick check for canonical encoding.
upper := true
Expand Down
4 changes: 2 additions & 2 deletions internal/textproto/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ func TestIssue46363(t *testing.T) {
r, w := net.Pipe()
go func() {
// ReadMIMEHeader calls canonicalMIMEHeaderKey, which reads from commonHeader
NewConn(r).ReadMIMEHeader()
_, _ = NewConn(r).ReadMIMEHeader()
}()
w.Write([]byte("A: 1\r\nB: 2\r\nC: 3\r\n\r\n"))
_, _ = w.Write([]byte("A: 1\r\nB: 2\r\nC: 3\r\n\r\n"))

// CanonicalMIMEHeaderKey calls commonHeaderOnce.Do(initCommonHeader) which initializes commonHeader
CanonicalMIMEHeaderKey("a")
Expand Down
12 changes: 6 additions & 6 deletions internal/textproto/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var dotcrnl = []byte{'.', '\r', '\n'}
func (w *Writer) PrintfLine(format string, args ...any) error {
w.closeDot()
fmt.Fprintf(w.W, format, args...)
w.W.Write(crnl)
_, _ = w.W.Write(crnl)
return w.W.Flush()
}

Expand Down Expand Up @@ -73,7 +73,7 @@ func (d *dotWriter) Write(b []byte) (n int, err error) {
d.state = wstateData
if c == '.' {
// escape leading dot
bw.WriteByte('.')
_ = bw.WriteByte('.')
}
fallthrough

Expand All @@ -82,7 +82,7 @@ func (d *dotWriter) Write(b []byte) (n int, err error) {
d.state = wstateCR
}
if c == '\n' {
bw.WriteByte('\r')
_ = bw.WriteByte('\r')
d.state = wstateBeginLine
}

Expand All @@ -107,13 +107,13 @@ func (d *dotWriter) Close() error {
bw := d.w.W
switch d.state {
default:
bw.WriteByte('\r')
_ = bw.WriteByte('\r')
fallthrough
case wstateCR:
bw.WriteByte('\n')
_ = bw.WriteByte('\n')
fallthrough
case wstateBeginLine:
bw.Write(dotcrnl)
_, _ = bw.Write(dotcrnl)
}
return bw.Flush()
}

0 comments on commit 67b5cbe

Please sign in to comment.