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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid index if no values #1465

Open
i23098 opened this issue Jan 4, 2024 · 0 comments
Open

Invalid index if no values #1465

i23098 opened this issue Jan 4, 2024 · 0 comments

Comments

@i23098
Copy link

i23098 commented Jan 4, 2024

Hi! 馃憢

Firstly, thanks for your work on this project! 馃檪

Today I used patch-package to patch @react-md/[email protected] for the project I'm working on.

I have a dropdown that has no values in some cases (probably the best would be to not show the empty dropdown but that's how I got this error triggered). If typing with the dropdown open it will fail in react-md code as it will try to access the array in an invalid index. endIndex should not be above the values array length...

Here is the diff that solved my problem:

diff --git a/node_modules/@react-md/utils/es/search/findMatchIndex.js b/node_modules/@react-md/utils/es/search/findMatchIndex.js
index fab3aa8..60b3795 100644
--- a/node_modules/@react-md/utils/es/search/findMatchIndex.js
+++ b/node_modules/@react-md/utils/es/search/findMatchIndex.js
@@ -43,7 +43,7 @@ export function findMatchIndex(value, values, startIndex, isSelfMatchable) {
     if (isSelfMatchable === void 0) { isSelfMatchable = true; }
     var index = findMatchInRange(value, values, startIndex + 1, values.length);
     if (index === -1) {
-        var endIndex = startIndex + (isSelfMatchable ? 1 : 0);
+        var endIndex = Math.min(startIndex + (isSelfMatchable ? 1 : 0), values.length);
         index = findMatchInRange(value, values, 0, endIndex);
     }
     return index;

This issue body was partially generated by patch-package.

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

No branches or pull requests

1 participant