fix(GODT-3151): Only modify HTML Meta content if UTF-8 charset override is needed.

This commit is contained in:
Romain LE JEUNE
2023-12-04 10:37:19 +01:00
parent a8f270405f
commit 9efaf9184c
4 changed files with 60 additions and 15 deletions

View File

@ -18,6 +18,7 @@
package parser
import (
"reflect"
"strconv"
"strings"
"testing"
@ -71,3 +72,45 @@ func getSectionNumber(s string) (part []int) {
return
}
func TestPart_ConvertMetaCharset(t *testing.T) {
tests := []struct {
name string
body string
wantErr bool
wantSame bool
}{
{
"html no meta",
"<body></body>",
false,
true,
},
{
"html meta no charset",
"<header><meta name=ProgId content=Word.Document></header><body><meta></body>",
false,
true,
},
{
"html meta UTF-8 charset",
"<header><meta charset=UTF-8></header><body><meta></body>",
false,
true,
},
{
"html meta not UTF-8 charset",
"<header><meta charset=UTF-7></header><body><meta></body>",
false,
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var p = Part{Body: []byte(tt.body)}
err := p.ConvertMetaCharset()
assert.Equal(t, tt.wantErr, err != nil)
assert.Equal(t, tt.wantSame, reflect.DeepEqual([]byte(tt.body), p.Body))
})
}
}