Skip to content
This repository has been archived by the owner on Mar 16, 2020. It is now read-only.

fix encoding #347

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"math/rand"
"net/http"
"net/url"
"regexp"
"strings"
"time"
"unicode/utf8"
Expand Down Expand Up @@ -397,6 +398,12 @@ func ParseFeed(c appengine.Context, contentType, origUrl, fetchUrl string, body
}
if enc != encoding.Nop {
cr = nilCharsetReader
preview := string(body[:128]) // <?xml version="1.0" encoding="windows-1251" ?>
r := regexp.MustCompile(`<\?xml.*encoding="(.*)".*\?>`)
rr := r.FindStringSubmatch(preview)
if len(rr) > 1 {
enc, _ = charset.Lookup(rr[1])
}
body, err = ioutil.ReadAll(transform.NewReader(bytes.NewReader(body), enc.NewDecoder()))
if err != nil {
return nil, nil, err
Expand Down