Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable xml:base URI resolution for RSS feeds #224

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions atom/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,10 @@ func (ap *Parser) parseAtomText(p *xpp.XMLPullParser) (string, error) {
(lowerType == "" && lowerMode == "") {
result, err = shared.DecodeEntities(result)
} else if strings.Contains(lowerType, "xhtml") {
result = ap.stripWrappingDiv(result)
result = StripWrappingDiv(result)
result, _ = shared.ResolveHTML(base, result)
} else if lowerType == "html" {
result = ap.stripWrappingDiv(result)
result = StripWrappingDiv(result)
result, err = shared.DecodeEntities(result)
if err == nil {
result, _ = shared.ResolveHTML(base, result)
Expand Down Expand Up @@ -734,7 +734,7 @@ func (ap *Parser) parseVersion(p *xpp.XMLPullParser) string {
return ""
}

func (ap *Parser) stripWrappingDiv(content string) (result string) {
func StripWrappingDiv(content string) (result string) {
result = content
r := strings.NewReader(result)
doc, err := goquery.NewDocumentFromReader(r)
Expand Down
25 changes: 0 additions & 25 deletions internal/shared/parseutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,6 @@ func FindRoot(p *xpp.XMLPullParser) (event xpp.XMLEventType, err error) {
return
}

// ParseText is a helper function for parsing the text
// from the current element of the XMLPullParser.
// This function can handle parsing naked XML text from
// an element.
func ParseText(p *xpp.XMLPullParser) (string, error) {
var text struct {
Type string `xml:"type,attr"`
InnerXML string `xml:",innerxml"`
}

err := p.DecodeElement(&text)
if err != nil {
return "", err
}

result := text.InnerXML
result = strings.TrimSpace(result)

if strings.Contains(result, CDATA_START) {
return StripCDATA(result), nil
}

return DecodeEntities(result)
}

// StripCDATA removes CDATA tags from the string
// content outside of CDATA tags is passed via DecodeEntities
func StripCDATA(str string) string {
Expand Down
Loading
Loading