Add workaround to handle some invalid dates

This commit is contained in:
Frédéric Guillot 2021-03-21 10:52:27 -07:00
parent 5877048749
commit e60e0ba3c4
3 changed files with 12 additions and 8 deletions

View file

@ -146,8 +146,8 @@ func (a *atom03Entry) entryHash() string {
type atom03Text struct { type atom03Text struct {
Type string `xml:"type,attr"` Type string `xml:"type,attr"`
Mode string `xml:"mode,attr"` Mode string `xml:"mode,attr"`
Data string `xml:",chardata"` CharData string `xml:",chardata"`
XML string `xml:",innerxml"` InnerXML string `xml:",innerxml"`
} }
func (a *atom03Text) String() string { func (a *atom03Text) String() string {
@ -155,16 +155,16 @@ func (a *atom03Text) String() string {
switch { switch {
case a.Mode == "xml": case a.Mode == "xml":
content = a.XML content = a.InnerXML
case a.Mode == "escaped": case a.Mode == "escaped":
content = a.Data content = a.CharData
case a.Mode == "base64": case a.Mode == "base64":
b, err := base64.StdEncoding.DecodeString(a.Data) b, err := base64.StdEncoding.DecodeString(a.CharData)
if err == nil { if err == nil {
content = string(b) content = string(b)
} }
default: default:
content = a.Data content = a.CharData
} }
if a.Type != "text/html" { if a.Type != "text/html" {

View file

@ -293,6 +293,8 @@ var invalidLocalizedDateReplacer = strings.NewReplacer(
"mai ", "May ", "mai ", "May ",
"jui ", "Jun ", "jui ", "Jun ",
"juin ", "June ", "juin ", "June ",
"Thurs,", "Thu,",
"Thur,", "Thu,",
) )
// Parse parses a given date string using a large // Parse parses a given date string using a large

View file

@ -178,6 +178,8 @@ func TestParseWeirdDateFormat(t *testing.T) {
"2018-10-23 04:07:42 +00:00", "2018-10-23 04:07:42 +00:00",
"5 August, 2019", "5 August, 2019",
"mar., 01 déc. 2020 16:11:02 +0000", "mar., 01 déc. 2020 16:11:02 +0000",
"Thurs, 15 Oct 2020 00:00:39 +0000",
"Thur, 19 Nov 2020 00:00:39 +0000",
} }
for _, date := range dates { for _, date := range dates {