WebReflection / linkedom

A triple-linked lists based DOM implementation.
https://webreflection.medium.com/linkedom-a-jsdom-alternative-53dd8f699311
ISC License
1.62k stars 78 forks source link

HTMLAnchorElement loses `rel` attribute after casting to string #274

Closed what1s1ove closed 1 month ago

what1s1ove commented 1 month ago

Hi there! Thank you for such a wonderful package!

Here is the problem:

let window = parseHTML(`
<!DOCTYPE html>
<html>
  <body><a href="https://www.google.com/">Google</a></body>
</html>
`)

let linkNode = window.document.querySelector(`a`)

linkNode.target = `_blank`

linkNode.rel = `noreferrer noopener` // losses `rel` attribute after casting to string

console.log(window.document.toString())
//  <html>
//    <body><a target="_blank" href="https://www.google.com/">Google</a></body>
//  </html>

linkNode.setAttribute(`rel`, `noreferrer noopener`) // works as expected 

console.log(window.document.toString())
//  <html>
//    <body><a rel="noreferrer noopener" target="_blank" href="https://www.google.com/">Google</a></body>
//  </html>

HTMLAnchorElement[rel] is not the read-only attribute according to the documentation, so I think it should behave the same as setAttribute('rel', // ...)

WebReflection commented 1 month ago

Yup, nothing in here indeed: https://github.com/WebReflection/linkedom/blob/main/esm/html/anchor-element.js ... mind a PR?

what1s1ove commented 1 month ago

Yup, nothing in here indeed: https://github.com/WebReflection/linkedom/blob/main/esm/html/anchor-element.js ... mind a PR?

Hey @WebReflection ! Thank you for the answer!

I will take a look today a bit later 🙏

WebReflection commented 1 month ago

I should probably have a script that vomits out per each class accessors so that it's easy to have a list and compare/fix all nodes with special treatment ... until then though ... this is a copy & paste of target or type, it should be an easy PR

what1s1ove commented 1 month ago

I should probably have a script that vomits out per each class accessors so that it's easy to have a list and compare/fix all nodes with special treatment ... until then though ... this is a copy & paste of target or type, it should be an easy PR

Sure! I've been busy with other projects, but I've just created a PR 🙂

I should probably have a script that vomits out per each class accessors so that it's easy to have a list and compare/fix all nodes with special treatment

That would be a great improvement over time!