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

View file

@ -293,6 +293,8 @@ var invalidLocalizedDateReplacer = strings.NewReplacer(
"mai ", "May ",
"jui ", "Jun ",
"juin ", "June ",
"Thurs,", "Thu,",
"Thur,", "Thu,",
)
// 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",
"5 August, 2019",
"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 {