Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fontmap] update Replacer for string normalization by handling null byte removal #171

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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