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

Make isArrayLike check more precise to avoid false positives #1520

Merged
merged 5 commits into from
May 17, 2018

Conversation

acusti
Copy link
Contributor

@acusti acusti commented May 9, 2018

Fixes #1438

Update isArrayLike to check for:

  • a numeric length
  • confirm that it has the length - 1 key set (even if it is undefined)
  • if length is 0, then check that it doesn’t have any other properties other than length

The “accepts an array-like” tests in List.ts and Set.ts both used an array-like object that has a length of 3 and a value set at index 1. This fails the updated logic, which verifies instead that there is a value set at the final index, as opposed to any arbitrary possible index. So, I updated those tests to have a value set at the final index in the array-like objects.

I also expanded the Seq.ts “accepts an array-like” test to include:

  • an example with a plain object that has a length but is not array-like, and so shouldn’t be converted to a List ({ length: 1, foo: 'bar' })
  • an example with a plain object that looks like an empty array and should be converted to a List ({ length: 0 })

Verify that a value is array-like by checking for
a numeric length and by confirming that it has the
length - 1 key set (even if it is undefined). If
length is 0, then check that it doesn’t have any
other properties other than length
@leebyron leebyron merged commit b29b484 into immutable-js:master May 17, 2018
@acusti acusti deleted the array-like branch March 31, 2022 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants