fix: handle splice with single argument#12194
Open
veeceey wants to merge 1 commit intochartjs:masterfrom
Open
Conversation
When Array.splice is called with only the start argument (e.g. splice(0)), the deleteCount parameter is omitted. This caused arguments.length - 2 to evaluate to -1, which was truthy and led to _insertElements being called with a negative count, throwing a RangeError: Invalid array length. Fix by checking newCount > 0 instead of just truthy. Fixes chartjs#12191
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #12191
When
Array.prototype.spliceis called with only thestartargument (e.g..splice(0)to clear an array), the second argument (deleteCount) is omitted. In_onDataSplice, this causedarguments.length - 2to evaluate to-1, which is truthy and led to_insertElementsbeing called with a negative count, throwing:The fix changes the condition from
if (newCount)toif (newCount > 0)so that negative values from omitted arguments are properly ignored.Added a test that verifies
data.splice(0)works without throwing.