Skip to content

Commit

Permalink
Atom: use correct xml:base for decoded elements
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cristoper committed Feb 24, 2024
1 parent 454d6a3 commit 23bc3fa
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions atom/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,20 @@ func (ap *Parser) parseAtomText(p *xpp.XMLPullParser) (string, error) {
InnerXML string `xml:",innerxml"`
}

// DecodeElement pops the base stack if the element contains an xml:base
// attribute, so we need to save and restore it before resolving any
// relative URLs below
oldBase := p.BaseStack
err := p.DecodeElement(&text)
if err != nil {
return "", err
}
newBase := p.BaseStack
p.BaseStack = oldBase
defer func() {
// pop base when we're done with the decoded element
p.BaseStack = newBase
}()

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

0 comments on commit 23bc3fa

Please sign in to comment.