mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-16 23:26:44 +00:00
fix(GODT-3151): Only modify HTML Meta content if UTF-8 charset override is needed.
This commit is contained in:
@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user