Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Stop the iteration of an exhausted, unknown-sized sequence when slicing #1324

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

Merged
merged 1 commit into from
Oct 2, 2017

Conversation

philipp-spiess
Copy link
Contributor

Fixes #1256

This PR fixes a bug with the slice operator that caused non-value
iterators of an unknown sized sequence to continue although the source
sequence was exhausted, eventually accessing the value of a key/value
pair that does not exist.

The issue did not happen with fixed sized sequences since we can
calculate resulting size in advance (as sliceSize) and bail out early.
For an unknown sized sequence, however, we can not know this size in
advance (see this comment: 1).

To solve this, we now bail out when we encounter a completed iterator
before proceeding to process it further.

This PR fixes a bug with the slice operator that caused non value
iterators of an unknown sized sequence to continue although the source
sequence was exhausted, eventually accessing the value of a key/value
pair that does not exist.

The issue did not happen with fixed sized sequences since we can
calculate resulting size in advance (as `sliceSize`) and bail out early.
For an unknown sized sequence however, we can not know this size in
advance (see this comment: [1]).

To solve this, we now bail out when we encounter a completed iterator
before proceeding to process it further.

[1]: https://github.com/facebook/immutable-js/blob/27b231c8952366ddb96ab2a20d1eb351b3c8719e/src/Operations.js#L427-L428
@leebyron leebyron merged commit e4ca4ce into immutable-js:master Oct 2, 2017
@leebyron
Copy link
Collaborator

leebyron commented Oct 2, 2017

Great, thanks for adding a test!

@philipp-spiess philipp-spiess deleted the philipp/seq-length branch October 2, 2017 20:45
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.

Seq iterator has an undefined size, causing it to access elements that don't exist
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.