Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAttribute() doesn't return null for not existing attributes #46

Closed
domekomi opened this issue May 4, 2020 · 2 comments · Fixed by #477 or #482
Closed

getAttribute() doesn't return null for not existing attributes #46

domekomi opened this issue May 4, 2020 · 2 comments · Fixed by #477 or #482
Labels
breaking change Some thing that requires a version bump due to breaking changes bug Something isn't working spec:DOM-Level-2 https://www.w3.org/TR/DOM-Level-2-Core/
Milestone

Comments

@domekomi
Copy link

domekomi commented May 4, 2020

getAttribute() and related methods don't return null for not existing attributes.
Methods below should be fixed to return null.

  • NamedNodeMap.prototype.getNamedItem()
  • Element.prototype.getAttribute()
  • Element.prototype.getAttributeNode()
  • Element.prototype.getAttributeNS()
@domekomi domekomi closed this as completed May 4, 2020
@domekomi domekomi changed the title getAttribute() doesn getAttribute() doesn't return null for not existing attributes May 4, 2020
@domekomi domekomi reopened this May 4, 2020
@karfau karfau added documentation Improvements or additions to documentation help-wanted External contributions welcome needs investigation Information is missing and needs to be researched labels Jan 21, 2021
@karfau karfau added this to the 0.6.0 milestone Jan 21, 2021
@karfau karfau added breaking change Some thing that requires a version bump due to breaking changes bug Something isn't working spec:DOM-Level-2 https://www.w3.org/TR/DOM-Level-2-Core/ and removed documentation Improvements or additions to documentation help-wanted External contributions welcome needs investigation Information is missing and needs to be researched labels Aug 23, 2021
@zhiqingchen
Copy link

"@xmldom/xmldom": "0.8.2",

Also have this problem

karfau pushed a commit that referenced this issue Feb 25, 2023
BREAKING CHANGE: `Element.getAttribute` and `Element.getAttributeNS`
return `null` if the attribute doesn't exist

closes #46
https://dom.spec.whatwg.org/#dom-element-getattribute
@karfau
Copy link
Member

karfau commented Mar 19, 2023

Reopening this since I'm still working on it in #482

karfau added a commit that referenced this issue Jun 9, 2023
- proper order in finding attributes (only affects duplicate attributes,
which can only be created manually and anyways produce invalid XML)
- properly remove item from previous last index (was not iterated over
but the reference was kept)
- set `ownerElement` to `null` even when `ownerElement.ownerDocument` is
not set (which is an edge case which doesn't happen when parsing XML)
- throw `DOMException` when there is no matching attribute
- add test coverage
- add doc comments regarding differences to the specification that still
exist:
  - no named property indices support
- add validation of qualified names in `Element` API which can throw
`DOMException` as declared in the specs
- always initialize required properties with `null` in `Attr`
constructor

BREAKING CHANGES: Mainly not throwing when removing an attribute that
doesn't exist and other behavior that was different from the
specification.

closes #46
see #477
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Some thing that requires a version bump due to breaking changes bug Something isn't working spec:DOM-Level-2 https://www.w3.org/TR/DOM-Level-2-Core/
Projects
Status: Done
3 participants