Skip to content

fix(xmlelement): resolve namespaced XML attributes by prefix#898

Open
Noethix55555 wants to merge 1 commit into
gocolly:masterfrom
Noethix55555:fix/xml-namespace-attr
Open

fix(xmlelement): resolve namespaced XML attributes by prefix#898
Noethix55555 wants to merge 1 commit into
gocolly:masterfrom
Noethix55555:fix/xml-namespace-attr

Conversation

@Noethix55555

Copy link
Copy Markdown

Fixes #897.

XMLElement.Attr, ChildAttr and ChildAttrs matched xmlquery attributes only on Name.Local, ignoring the namespace. With both a namespaced and an unprefixed attribute sharing a local name (for example ns:id and id), a bare lookup could return the namespaced value, and a prefixed attribute could not be requested at all.

This matches the full prefix:local name first and falls back to the bare local name, so existing lookups of unprefixed attributes are unchanged.

Attr("id")    => "local"  (was "42")
Attr("ns:id") => "42"     (was "")

Added TestXMLNamespacedAttr, which fails on the previous code and passes with the fix. Existing attribute tests still pass.

XMLElement.Attr, ChildAttr and ChildAttrs matched xmlquery attributes
only on Name.Local, ignoring the namespace. When an element carried a
namespaced and an unprefixed attribute sharing a local name (for example
ns:id and id), the namespaced one could be returned for a bare local
lookup, and a prefixed attribute could not be requested at all.

Match the full prefix:local name first and fall back to the bare local
name, preserving existing behaviour for unprefixed attributes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XMLElement attribute lookups ignore XML namespaces

1 participant