From 2e9c6f5723b0df9afc1392fd00e44683832d6abc Mon Sep 17 00:00:00 2001 From: Martin Hutchinson Date: Tue, 16 Jul 2024 17:31:50 +0100 Subject: [PATCH] Fix extra spaces on last leaf in bundle (#1189) Fixes #1188. --- clone/cmd/sumdbclone/internal/client/sumdb.go | 6 +++++- clone/cmd/sumdbclone/internal/client/sumdb_test.go | 3 +++ go.mod | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/clone/cmd/sumdbclone/internal/client/sumdb.go b/clone/cmd/sumdbclone/internal/client/sumdb.go index 0cf0aabfc..67f288f8d 100644 --- a/clone/cmd/sumdbclone/internal/client/sumdb.go +++ b/clone/cmd/sumdbclone/internal/client/sumdb.go @@ -121,10 +121,14 @@ func (c *SumDBClient) tilePath(offset int) string { return nStr } +// dataToLeaves splits the raw bytes received when requesting a data +// tile into the constituent leaf data chunks. The splitting is performed +// based on two consecutive newlines, and each returned leaf terminates +// with a single newline. func dataToLeaves(data []byte) [][]byte { leaves := bytes.Split(data, []byte{'\n', '\n'}) for i, l := range leaves { - leaves[i] = append(l, '\n') + leaves[i] = append(bytes.TrimSpace(l), '\n') } return leaves } diff --git a/clone/cmd/sumdbclone/internal/client/sumdb_test.go b/clone/cmd/sumdbclone/internal/client/sumdb_test.go index c2faecccc..580b7a6bd 100644 --- a/clone/cmd/sumdbclone/internal/client/sumdb_test.go +++ b/clone/cmd/sumdbclone/internal/client/sumdb_test.go @@ -63,6 +63,9 @@ func TestLeavesAtOffset(t *testing.T) { if l[len(l)-1] != '\n' { t.Errorf("expected string terminating in newline, got: %x", l) } + if l[len(l)-2] == '\n' { + t.Errorf("expected string terminating in single newline, but got: %x", l) + } expStart := "golang.org/x/" if got, want := string(l[:len(expStart)]), expStart; got != want { t.Errorf("got prefix '%s', wanted '%s'", got, want) diff --git a/go.mod b/go.mod index b521d0af5..297e6a81a 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,7 @@ module github.com/google/trillian-examples -go 1.21 +go 1.21.0 + toolchain go1.22.4 require (