From 19676b2703e18204e501037c8d9043cb3cbdcabf Mon Sep 17 00:00:00 2001 From: David Date: Sun, 27 Jun 2021 11:24:08 -0700 Subject: [PATCH] Fix #650: checkIndexBounds off by 1 validation --- packages/react-swipeable-views-core/src/checkIndexBounds.js | 4 ++-- .../react-swipeable-views-core/src/checkIndexBounds.test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-swipeable-views-core/src/checkIndexBounds.js b/packages/react-swipeable-views-core/src/checkIndexBounds.js index 9007ee87..efe5ed86 100644 --- a/packages/react-swipeable-views-core/src/checkIndexBounds.js +++ b/packages/react-swipeable-views-core/src/checkIndexBounds.js @@ -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}].`, ); }; diff --git a/packages/react-swipeable-views-core/src/checkIndexBounds.test.js b/packages/react-swipeable-views-core/src/checkIndexBounds.test.js index 8be00318..bc37de63 100644 --- a/packages/react-swipeable-views-core/src/checkIndexBounds.test.js +++ b/packages/react-swipeable-views-core/src/checkIndexBounds.test.js @@ -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].', ); }); });