Skip to content

Commit

Permalink
Escape non-ASCII characters in package history
Browse files Browse the repository at this point in the history
  • Loading branch information
silkeh committed Apr 1, 2024
1 parent 4d9d8e2 commit d4e40b8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion builder/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -97,7 +98,7 @@ func NewPackageUpdate(commit *object.Commit, objectID string) *PackageUpdate {
Commit: commit.Hash,
Author: signature.Name,
AuthorEmail: signature.Email,
Body: commit.Message,
Body: toASCII(commit.Message),
Time: signature.When,
ObjectID: objectID,
}
Expand All @@ -112,6 +113,20 @@ func NewPackageUpdate(commit *object.Commit, objectID string) *PackageUpdate {
return update
}

func toASCII(s string) string {
var enc string

for _, r := range s {
if r > 127 {
enc += strconv.QuoteRuneToASCII(r)
} else {
enc += string(r)
}
}

return enc
}

// CatGitBlob will return the contents of the given entry.
func CatGitBlob(repo *git.Repository, entry *object.TreeEntry) ([]byte, error) {
obj, err := repo.BlobObject(entry.Hash)
Expand Down

0 comments on commit d4e40b8

Please sign in to comment.