Skip to content

fix(dom): prevent iteration over deleted items#514

Merged
karfau merged 2 commits into
masterfrom
499
Jul 19, 2023
Merged

fix(dom): prevent iteration over deleted items#514
karfau merged 2 commits into
masterfrom
499

Conversation

@karfau

@karfau karfau commented Jul 16, 2023

Copy link
Copy Markdown
Member
  • NodeList.item now checks the length attribute before accessing the item at a provided index and returns null it the index is out of range
  • when updating LiveNodeList (as part of accessing the item method) and the new length is shorter then the current one, any references on indexes following the index starting from length are deleted, and null is returned instead of undefined
  • added some exports to the lib/dom.js module to enable testing

fixes #499

@karfau karfau added this to the 0.9.0 milestone Jul 16, 2023
Comment thread test/dom/node-list.test.js Fixed
@karfau

karfau commented Jul 16, 2023

Copy link
Copy Markdown
Member Author

@qtow from what I understood in your issue report, this should fix it in all the ways I could think of.

Do you have a way to verify it before landing the PR? Or would you suggest to add any test?
(I just made sure the changed lines are covered by tests.)

If you are not able to, I can land and release it as part of the next pre-release for 0.9.0 and once you verified that, I would provide a backports for the versions 0.8 and 0.7

@karfau karfau merged commit 7cef79e into master Jul 19, 2023
@karfau karfau deleted the 499 branch July 19, 2023 10:27
karfau added a commit that referenced this pull request Jul 19, 2023
- `NodeList.item` now checks the `length` attribute before accessing the
item at a provided index and returns `null` it the index is out of range
- when updating `LiveNodeList` (as part of accessing the `item` method)
and the new `length` is shorter then the current one, any references on
indexes following the index starting from `length` are `delete`d, and
`null` is returned instead of `undefined`
- added some exports to the `lib/dom.js` module to enable testing

fixes #499
karfau added a commit that referenced this pull request Jul 19, 2023
- `NodeList.item` now checks the `length` attribute before accessing the
item at a provided index and returns `null` it the index is out of range
- when updating `LiveNodeList` (as part of accessing the `item` method)
and the new `length` is shorter then the current one, any references on
indexes following the index starting from `length` are `delete`d, and
`null` is returned instead of `undefined`
- added some exports to the `lib/dom.js` module to enable testing

fixes #499
@karfau

karfau commented Jul 19, 2023

Copy link
Copy Markdown
Member Author

The fix landed in 0.7 (lts), 0.8 (latest) and 0.9 (next)

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.

NodeList.item() returns removed nodes

2 participants