Skip to content

Using for...in to loop on Arrays may break if Array.prototype is modified by the app #1539

Closed

Description

@efattal

Problem:

I would like to use Sortable in a WebComponent inside an app where old frameworks that I can hardly remove (PrototypeJS and ExtJS 3.4) override Array.prototype. Hence, Sortable breaks on drag-dropping when looping on arrays (like _detectNearestEmptySortable on sortables).

I submit a Pull Request that fixes the issue.
#1540

JSBin/JSFiddle demonstrating the problem:

http://jsfiddle.net/efattal/zv2h8bnx/1/

Activity

  1. added 2 commits that reference this issue on Jun 14, 2019
  2. imnottherobot commented on Jun 17, 2019

    @imnottherobot

    I have same issue

  3. owen-m1 commented on Jun 17, 2019

    @owen-m1
    Member

    Why does that even break the for...in loop?

  4. efattal commented on Jun 17, 2019

    @efattal
    Author

    It's reproducible in the fiddle. Just look at JS errors in devtools and you'll see. for...in gets added members as keys while the code is only expecting positions in the array. Hence it gets undefined values from the array.

  5. added a commit that references this issue on Jun 23, 2019
  6. owen-m1 commented on Jun 23, 2019

    @owen-m1
    Member

    Solved in commit 854fed7.

  7. added a commit that references this issue on Nov 18, 2019
  8. added a commit that references this issue on Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions