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

Bugfix: TypeError in Interaction due to out-of-bounds index #11991

Merged
merged 1 commit into from
Jan 5, 2025

Conversation

marisst
Copy link
Contributor

@marisst marisst commented Jan 4, 2025

I have introduced a bug in my previous pull request #11986. This PR fixes it and adds 4 test cases to make sure it doesn't happen again.

If there is a line chart with the following dataset

data: [1, null, 2],
spanGaps: true,

and user hovers close to 2, then binarySearch wrapper returns hi: 4 for nearest interaction, which is an index not existing in the dataset (it only has 3 elements). An Uncaught TypeError is thrown at core.interaction.js:82.

image

I apologize for not being diligent enough and introducing this error. The end - 1 was needed in helpers.extras.ts, because + 1 is added to it in line 119 (to the left in screenshot below), but in core.interaction.js it was not needed, because + 1 is not added to the result (to the right in screenshot below).
image

@LeeLenaleee LeeLenaleee added this to the Version 4.4.8 milestone Jan 5, 2025
@etimberg etimberg merged commit 97b564b into chartjs:master Jan 5, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants