Skip to content

Comments

Fix #12191: splice with single argument throws RangeError#12202

Open
cobyfrombrooklyn-bot wants to merge 1 commit intochartjs:masterfrom
cobyfrombrooklyn-bot:fix-issue-12191
Open

Fix #12191: splice with single argument throws RangeError#12202
cobyfrombrooklyn-bot wants to merge 1 commit intochartjs:masterfrom
cobyfrombrooklyn-bot:fix-issue-12191

Conversation

@cobyfrombrooklyn-bot
Copy link

When calling data.splice(0) with only one argument (which should clear the array), _onDataSplice computed newCount as arguments.length - 2 = -1, causing a RangeError: Invalid array length.

Fix

Changed arguments.length - 2 to Math.max(0, arguments.length - 2) in core.datasetController.js to clamp newCount to zero when fewer than 2 arguments are passed.

Test

Added test case should handle splice with a single argument without throwing (issue #12191) in core.datasetController.tests.js that:

  1. Creates a chart with 6 data points
  2. Calls data.splice(0) (single argument)
  3. Verifies no error is thrown
  4. Verifies meta.data.length and data.length are both 0

Test fails without the fix (RangeError), passes with it. Full test suite passes on macOS ARM (Apple Silicon, ChromeHeadless).

When calling data.splice(0) with only one argument, _onDataSplice
computed newCount as arguments.length - 2 = -1, which is an invalid
array length. Fixed by using Math.max(0, ...) to clamp to zero.

Fixes chartjs#12191
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 this pull request may close these issues.

1 participant