diff --git a/v3/common/type.go b/v3/common/type.go index 26d59de..e79bcb9 100644 --- a/v3/common/type.go +++ b/v3/common/type.go @@ -156,11 +156,11 @@ type SignedRational struct { } func isPrintableText(s string) bool { - - // TODO(dustin): Add text - for _, c := range s { - if unicode.IsPrint(rune(c)) == false { + // unicode.IsPrint() returns false for newline characters. + if c == 0x0d || c == 0x0a { + continue + } else if unicode.IsPrint(rune(c)) == false { return false } } diff --git a/v3/common/type_test.go b/v3/common/type_test.go index b3953d1..bc9008d 100644 --- a/v3/common/type_test.go +++ b/v3/common/type_test.go @@ -411,3 +411,27 @@ func TestTranslateStringToType__InvalidType(t *testing.T) { // log.Panicf("from-string encoding for type not supported; this shouldn't happen: [%s]", tagType.String()) // return nil, nil // } + +func TestIsPrintableText_letters(t *testing.T) { + if isPrintableText("abc") != true { + t.Fatalf("Printable text interpreted as nonprintable.") + } +} + +func TestIsPrintableText_space(t *testing.T) { + if isPrintableText(" ") != true { + t.Fatalf("Printable text interpreted as nonprintable.") + } +} + +func TestIsPrintableText_newlines(t *testing.T) { + if isPrintableText("\r\n") != true { + t.Fatalf("Printable text interpreted as nonprintable.") + } +} + +func TestIsPrintableText_punctuationAndSymbols(t *testing.T) { + if isPrintableText(",:-/$©") != true { + t.Fatalf("Printable text interpreted as nonprintable.") + } +}