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

checkIndexBounds off by 1 validation #650

Open
1 task done
davidnx opened this issue Jun 27, 2021 · 0 comments · May be fixed by #651
Open
1 task done

checkIndexBounds off by 1 validation #650

davidnx opened this issue Jun 27, 2021 · 0 comments · May be fixed by #651

Comments

@davidnx
Copy link

davidnx commented Jun 27, 2021

checkIndexBounds is too lenient and allows setting indexes from 0 .. count inclusive, whereas really the only valid values are 0 .. (count-1).

warning(
index >= 0 && index <= childrenCount,
`react-swipeable-view: the new index: ${index} is out of bounds: [0-${childrenCount}].`,
);

  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior

The warning is only produced after setting index to children.length + 1:

Here is an example warning I see when I set index = 4 having only 3 children:

Warning: react-swipeable-view: the new index: 4 is out of bounds: [0-3].

Expected Behavior

Setting index to exactly children.length should already produce a warning. The warning message should also show the correct range of values.

E.g. setting index to 3 should produce this warning when there are only 3 children:

Warning: react-swipeable-view: the new index: 3 is out of bounds: [0-2].

Steps to Reproduce

This should produce a warning, but it doesn't:

<SwipeableViews index={3}>
  <div>A</div>
  <div>B</div>
  <div>C</div>
</SwipeableViews>

Context

This is a minor dev nuisance, where the lenience of react-swipable-views is potentially allowing a dev to not detect code defects.

Your Environment

Tech Version
react-swipeable-views 0.14.0
React 17.0.2
platform Web
davidnx added a commit to davidnx/react-swipeable-views that referenced this issue Jun 27, 2021
@davidnx davidnx linked a pull request Jun 27, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant