question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`attr` adds duplicate namespaced attribute in 1.0.0-rc.5

See original GitHub issue

Example:

<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:

image

In 1.0.0-rc.3:

  • When setting attribute xlink:href, it creates another attribute href but properly setting the xlink: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 name xlink:href making that attribute duplicate and thus invalid XML
  • Child attributes are properly processed, like font-family and xml:space

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
5saviahvcommented, Feb 3, 2021

Interesting, at first look it seems like parse5 serializer is who adds those prefixes there. Cheerio wont handle namespaced attributes correctly.

0reactions
fb55commented, Jun 2, 2021

I just tried to replicate this on the latest version:

const d = $.load(
  `<a xlink:href="https://certificateUrl"><text xml:space="preserve"></text></a>`,
  null,
  false
);

d('a').attr('xlink:href', 'boohoo');

expect(d.html()).toBe(
  `<a xlink:href="boohoo"><text xml:space="preserve"></text></a>`
);

Looks like this issue has been resolved.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found