Skip to content

Commit

Permalink
Fix extra spaces on last leaf in bundle (#1189)
Browse files Browse the repository at this point in the history
Fixes #1188.
  • Loading branch information
mhutchinson committed Jul 16, 2024
1 parent a21ad69 commit 2e9c6f5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion clone/cmd/sumdbclone/internal/client/sumdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions clone/cmd/sumdbclone/internal/client/sumdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/google/trillian-examples

go 1.21
go 1.21.0

toolchain go1.22.4

require (
Expand Down

0 comments on commit 2e9c6f5

Please sign in to comment.