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

RangeError: Invalid array length #875

Closed
lovetingyuan opened this issue Apr 23, 2023 · 1 comment · Fixed by #886
Closed

RangeError: Invalid array length #875

lovetingyuan opened this issue Apr 23, 2023 · 1 comment · Fixed by #886
Labels
bug Something isn't working

Comments

@lovetingyuan
Copy link

Describe the bug
I use innerHTML to insert a piece of html, then error occurs.

To Reproduce
Steps to reproduce the behavior:

just use node to run code below:

import { GlobalRegistrator } from '@happy-dom/global-registrator'
GlobalRegistrator.register()
document.write(`<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <title></title>
  </head>
  <body>
    <div id="app">
    </div>
  </body>
</html>
`)
document.getElementById('app').innerHTML = `<a name="length"></a>`

Expected behavior
no error

Screenshots


   this[name] = this._namedItems[name][0];
                           ^

RangeError: Invalid array length
    at HTMLCollection._appendNamedItem (/mnt/c/node_modules/.pnpm/happy-dom@9.9.2/node_modules/happy-dom/lib/nodes/element/HTMLCollection.js:43:28)
    at ElementUtility.appendChild (/mnt/node_modules/.pnpm/happy-dom@9.9.2/node_modules/happy-dom/lib/nodes/element/ElementUtility.js:43:43)
    at DocumentFragment.appendChild (/mnt/c/node_modules/.pnpm/happy-dom@9.9.2/node_modules/happy-dom/lib/nodes/document-fragment/DocumentFragment.js:146:41)
    at XMLParser.parse (/mnt/c/node_modules/.pnpm/happy-dom@9.9.2/node_modules/happy-dom/lib/xml-parser/XMLParser.js:91:41)
    at set innerHTML [as innerHTML] (/mnt/c/node_modules/.pnpm/happy-dom@9.9.2/node_modules/happy-dom/lib/nodes/element/Element.js:200:48)
    at render (file:///mnt/c/src/test.mjs:74:46)

Device:

  • windows 11
  • node 18.15.0

Additional context
I think the key point of the bug is the attribute name="length", if I change the attribute name("name") or the value("length",) the bug disappears.

@lovetingyuan lovetingyuan added the bug Something isn't working label Apr 23, 2023
capricorn86 added a commit that referenced this issue May 2, 2023
…ion related to id/name of elements colliding with class properties and methods.
capricorn86 added a commit that referenced this issue May 2, 2023
…-length

#875@patch: Fixes issue in HTMLCollection and HTMLFormControlsCollect…
@capricorn86
Copy link
Owner

Thank you for reporting @lovetingyuan! 🙂

The issue has been fixed now.

This was a pretty serious bug. Hopefully it is not common to use names or id:s with the same name as methods and properties of the HTMLCollection class.

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v9.10.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants