Skip to content

Commit

Permalink
Merge pull request #88 from buildbarn/bugfix/logsNullCheck
Browse files Browse the repository at this point in the history
utf8 encoding  for edge cases with build logs
  • Loading branch information
trey-ivy authored Feb 20, 2025
2 parents 19cb077 + 97334f4 commit 94f72e8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/summary/summarizer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package summary

import (
"bytes"
"context"
"encoding/base64"
"errors"
Expand All @@ -11,6 +12,7 @@ import (
"strconv"
"strings"
"time"
"unicode/utf8"

"github.com/google/uuid"
"google.golang.org/api/iterator"
Expand Down Expand Up @@ -183,13 +185,20 @@ func (s Summarizer) handleBuildProgress(progress *bes.Progress) {
if _, exists := uniqueLines[line]; !exists {
uniqueLines[line] = struct{}{}
if line != "" && line != "\n" {
s.summary.BuildLogs.WriteString(line + "\n")
if utf8.ValidString(line) {
s.summary.BuildLogs.WriteString(sanitizeUTF8(line) + "\n")
}
}
}
}
}
}

func sanitizeUTF8(s string) string {
bs := bytes.ReplaceAll([]byte(s), []byte{0}, []byte{})
return strings.ToValidUTF8(string(bs), "?")
}

// handleStarted
func (s Summarizer) handleStarted(started *bes.BuildStarted) {
var startedAt time.Time
Expand Down

0 comments on commit 94f72e8

Please sign in to comment.