From 7f1dd6c2b4c63ca5207ad33d9aeb97733c344984 Mon Sep 17 00:00:00 2001 From: Arran Ubels Date: Sun, 9 Oct 2022 17:02:31 +1100 Subject: [PATCH 1/3] Tests --- .github/workflows/test.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..a882731 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,28 @@ +on: [push, pull_request] +name: Test +jobs: + test: + strategy: + matrix: + go-version: [1.19.x] + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Checkout code + uses: actions/checkout@v2 + - name: Cache-Go + uses: actions/cache@v1 + with: + path: | + ~/go/pkg/mod # Module download cache + ~/.cache/go-build # Build cache (Linux) + ~/Library/Caches/go-build # Build cache (Mac) + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + - name: Test + run: go test ./... From 9b1b3b6784241cf6ce02f406ec8997be11f06f14 Mon Sep 17 00:00:00 2001 From: Arran Ubels Date: Sun, 9 Oct 2022 17:12:21 +1100 Subject: [PATCH 2/3] Valid header logic. --- entity.go | 3 +++ textproto/header.go | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/entity.go b/entity.go index a0858e5..b52e08f 100644 --- a/entity.go +++ b/entity.go @@ -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 diff --git a/textproto/header.go b/textproto/header.go index 10c04f3..eace386 100644 --- a/textproto/header.go +++ b/textproto/header.go @@ -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. @@ -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 } From 88d073923c5eb7fcecf8a6600bcede22cf8b94b7 Mon Sep 17 00:00:00 2001 From: Arran Ubels Date: Sun, 9 Oct 2022 17:13:33 +1100 Subject: [PATCH 3/3] Another build system is in place. --- .github/workflows/test.yml | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index a882731..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,28 +0,0 @@ -on: [push, pull_request] -name: Test -jobs: - test: - strategy: - matrix: - go-version: [1.19.x] - os: [ubuntu-latest] - runs-on: ${{ matrix.os }} - steps: - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go-version }} - - name: Checkout code - uses: actions/checkout@v2 - - name: Cache-Go - uses: actions/cache@v1 - with: - path: | - ~/go/pkg/mod # Module download cache - ~/.cache/go-build # Build cache (Linux) - ~/Library/Caches/go-build # Build cache (Mac) - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - - name: Test - run: go test ./...