From 9455e2b8fe26b593582a0018c18b3a1aa58f2afe Mon Sep 17 00:00:00 2001 From: chris <331548+cristoper@users.noreply.github.com> Date: Thu, 29 Feb 2024 20:28:56 -0700 Subject: [PATCH] Atom: use correct xml:base for decoded elements (#222) * Atom: use correct xml:base for decoded elements In order to keep tracking xml:base correctly, the goxpp's `DecodeElement` pops the BaseStack if the start element added a base (if any). That means the atom parser needs keep track of the base *before* calling `DecodeElement` to use for resolving relative URLs within the decoded element. Without this fix, elements with xml:base attributes will be erroneously resolved with the parent xml:base. * Depend on updated goxpp version without xml:base bug * Resolve xml:base URLs without switching out the BaseStack This provides an equivalent fix that doesn't do any inelegant swapping out of the BaseStack. It also doesn't change `goxpp`'s public API by essentially copying `XmlBaseResolveUrl` to `gofeed`. --- atom/parser.go | 10 ++++++---- go.mod | 2 +- go.sum | 4 ++-- internal/shared/xmlbase.go | 29 +++++++++++++++++++++++++---- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/atom/parser.go b/atom/parser.go index 0908114..1908203 100644 --- a/atom/parser.go +++ b/atom/parser.go @@ -658,6 +658,8 @@ func (ap *Parser) parseAtomText(p *xpp.XMLPullParser) (string, error) { InnerXML string `xml:",innerxml"` } + // get current base URL before it is clobbered by DecodeElement + base := p.BaseStack.Top() err := p.DecodeElement(&text) if err != nil { return "", err @@ -672,7 +674,7 @@ func (ap *Parser) parseAtomText(p *xpp.XMLPullParser) (string, error) { if strings.Contains(result, "