Skip to content

Allows detection of end of end of input empty results #160

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ func ReadWithOptions(r io.Reader, opts *ReadOptions) (*Entity, error) {
if err != nil {
return nil, err
}
if !h.Valid() {
return nil, nil
}

lr.N = math.MaxInt64

Expand Down
9 changes: 9 additions & 0 deletions textproto/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ func (h *Header) Len() int {
return len(h.l)
}

// Valid returns if the data structure is valid, if it was initialized correctly
func (h *Header) Valid() bool {
return h.l != nil && h.m != nil
}

// Map returns all header fields as a map.
//
// This function is provided for interoperability with the standard library.
Expand Down Expand Up @@ -533,6 +538,10 @@ func ReadHeader(r *bufio.Reader) (Header, error) {

for {
kv, err := readContinuedLineSlice(r)
if kv == nil && len(fs) == 0 {
// Construct an invalid header.
return Header{}, err
}
if len(kv) == 0 {
return newHeader(fs), err
}
Expand Down