Skip to content

Commit

Permalink
[fontmap] update Replacer for string normalization by handling null b…
Browse files Browse the repository at this point in the history
…yte removal
  • Loading branch information
akiyosi committed Oct 30, 2024
1 parent bceaf9b commit c4b7854
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion font/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (fd *fontDescriptor) rawAspect() Aspect {
return Aspect{style, weight, stretch}
}

var rp = strings.NewReplacer(" ", "", "\t", "")
var rp = strings.NewReplacer(" ", "", "\t", "", "\x00", "")

// NormalizeFamily removes spaces and lower the given string.
func NormalizeFamily(family string) string { return rp.Replace(strings.ToLower(family)) }
Expand Down
1 change: 1 addition & 0 deletions fontscan/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func (fp *Footprint) deserializeFrom(data []byte) (int, error) {
if err != nil {
return 0, err
}
fp.Family = font.NormalizeFamily(fp.Family)
n += read
read, err = fp.Runes.deserializeFrom(data[n:])
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions fontscan/serialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
func Test_serializeFootprints(t *testing.T) {
input := []Footprint{
{
Family: "a strange one",
Family: font.NormalizeFamily("a strange \x00one"),
Runes: newRuneSet(1, 0, 2, 0x789, 0xfffee),
Scripts: ScriptSet{0, 1, 5, 0xffffff, language.Nabataean, language.Unknown},
Aspect: font.Aspect{Style: 1, Weight: 200, Stretch: 0.45},
Expand Down Expand Up @@ -71,7 +71,7 @@ func assertFontsetEquals(expected, got []Footprint) error {
func TestSerializeDeserialize(t *testing.T) {
for _, fp := range []Footprint{
{
Family: "a strange one",
Family: font.NormalizeFamily("a strange \x00one"),
Runes: newRuneSet(1, 0, 2, 0x789, 0xfffee),
Scripts: ScriptSet{0, 1, 5, 0xffffff},
Aspect: font.Aspect{Style: 1, Weight: 200, Stretch: 0.45},
Expand Down

0 comments on commit c4b7854

Please sign in to comment.