`attr` adds duplicate namespaced attribute in 1.0.0-rc.5
See original GitHub issueExample:
<a transform="translate(1135.9 750)" fill="#5293d5" xlink:href="https://certificateUrl">
<text id="certificateUrl" transform="scale(1,-1)" x="242.74602" y="545.25012" fill="#5293d5" font-family="'Open Sans'" font-size="100px" letter-spacing="0px" stroke-width="7.5" word-spacing="0px" style="font-feature-settings:normal;font-variant-caps:normal;font-variant-ligatures:normal;font-variant-numeric:normal;line-height:1.25" xml:space="preserve">
<tspan x="242.74602" y="545.25012" fill="#5293d5" font-family="'Open Sans'" font-size="100px" stroke-width="7.5" style="font-feature-settings:normal;font-variant-caps:normal;font-variant-ligatures:normal;font-variant-numeric:normal">https://certificateUrl</tspan>
</text>
</a>
Code:
const $ = cheerio.load(template);
// WARNING: in cheerio 1.0.0-rc.3 this worked properly, in cheerio 1.0.0-rc.5 it will clear the tag's contents
$('a[href="https://certificateUrl"]').attr('xlink:href', data.certificateUrl);
Please fix this behavior of attr
like jQuery.
Related to #1664.
Result:
In 1.0.0-rc.3:
- When setting attribute
xlink:href
, it creates another attributehref
but properly setting thexlink:href
one - Child attributes are mangled, specifically
font-family
xml:space
get turned into ->space
In 1.0.0-rc.5:
- When setting attribute
xlink:href
, it creates another attribute with same namexlink:href
making that attribute duplicate and thus invalid XML - Child attributes are properly processed, like
font-family
andxml:space
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Duplicate "attr" name issues when using multiple Android ...
This doesn't make any sense because each attribute is wrapped by a namespace defined by the name of the declare-styleable.
Read more >php - Reference - How do I handle Namespaces (Tags and ...
I have an XML document which contains multiple namespaces; how do I parse it with SimpleXML? My XML has a colon (":") in...
Read more >Encoder duplicates namespace tags · Issue #7535 · golang/go
This issue only occurs with namespaces. Normal attributes are handled correctly.
Read more >XML Schema: Understanding Namespaces - Oracle
Now let's examine how to create a new namespace and add elements and attributes to it using XML Schema. XML Schema is an...
Read more >Namespaces in XML 1.0 (Third Edition) - W3C
We envision applications of Extensible Markup Language (XML) where a single XML document may contain elements and attributes (here referred to ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Interesting, at first look it seems like parse5 serializer is who adds those prefixes there.Cheerio wont handle namespaced attributes correctly.I just tried to replicate this on the latest version:
Looks like this issue has been resolved.