Skip to content

Commit

Permalink
Fix oliviertassinari#650: checkIndexBounds off by 1 validation
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnx committed Jun 27, 2021
1 parent a12dd90 commit 19676b2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/react-swipeable-views-core/src/checkIndexBounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const checkIndexBounds = props => {
const childrenCount = React.Children.count(children);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ describe('checkIndexBounds', () => {

it('should warn when the index is out of bounds', () => {
checkIndexBounds({
index: 3,
index: 2,
children,
});
assert.strictEqual(consoleStub.callCount, 1);
assert.strictEqual(
consoleStub.args[0][0],
'Warning: react-swipeable-view: the new index: 3 is out of bounds: [0-2].',
'Warning: react-swipeable-view: the new index: 2 is out of bounds: [0-1].',
);
});
});

0 comments on commit 19676b2

Please sign in to comment.