You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Incorrect order of elements when using document.querySelectorAll under certain circumstances. See "Additional context" for a technical description.
Additional context
In the QuerySelector class, findAll method, when iterating through the elements, the position of every one is stored as a string using its index:
Given that individual characters are compared when sorting strings, items with an index of 10 to 19, 100 to 199 and so on will appear before items with index of 3, 4...
Something like adding leading zeroes to the position of the elements of every level up to the number of digits of children.length - 1 would fix the issue without changing the way they are sorted, but since performance is a selling point vs jsdom, maybe a more complex solution is preferable.
The text was updated successfully, but these errors were encountered:
The sorting mechanism was sorting incorrectly as it sorted by characters and numbers came in the wrong order (1, 10, 11, 2, 3, 4 etc.). The unit test did not cover this.
Describe the bug
Incorrect order of elements when using
document.querySelectorAll
under certain circumstances. See "Additional context" for a technical description.To Reproduce
Expected behavior
document.querySelectorAll
should return the elements in document order.Additional context
In the
QuerySelector
class,findAll
method, when iterating through the elements, the position of every one is stored as a string using its index:happy-dom/packages/happy-dom/src/query-selector/QuerySelector.ts
Line 224 in 2c62156
Later, in the
querySelectorAll
method, that position is used to sort the results:happy-dom/packages/happy-dom/src/query-selector/QuerySelector.ts
Line 62 in 2c62156
Given that individual characters are compared when sorting strings, items with an index of 10 to 19, 100 to 199 and so on will appear before items with index of 3, 4...
Something like adding leading zeroes to the position of the elements of every level up to the number of digits of
children.length - 1
would fix the issue without changing the way they are sorted, but since performance is a selling point vs jsdom, maybe a more complex solution is preferable.The text was updated successfully, but these errors were encountered: