fix: resolved invalid handling of undefined vals

This commit is contained in:
Sheen Capadngan
2024-04-26 01:22:09 +08:00
parent a41883137c
commit e555d3129d
@@ -141,9 +141,11 @@ export const InfisicalSecretInput = ({
// Get fragment inside currentReference // Get fragment inside currentReference
const searchFragment = isNested ? currentReference.split(".").pop() || "" : currentReference; const searchFragment = isNested ? currentReference.split(".").pop() || "" : currentReference;
const filteredListRef = currentListReference.filter((suggestionEntry) => const filteredListRef = currentListReference
suggestionEntry.name.toUpperCase().startsWith(searchFragment.toUpperCase()) .filter((suggestionEntry) =>
); suggestionEntry.name.toUpperCase().startsWith(searchFragment.toUpperCase())
)
.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
setListReference(filteredListRef); setListReference(filteredListRef);
}, [secrets, environment, debouncedCurrentReference]); }, [secrets, environment, debouncedCurrentReference]);
@@ -157,7 +159,7 @@ export const InfisicalSecretInput = ({
// find unclosed reference index less than the current cursor position // find unclosed reference index less than the current cursor position
let indexIter = -1; let indexIter = -1;
unclosedReferenceIndexMatches.forEach((index) => { unclosedReferenceIndexMatches.forEach((index) => {
if (index && index > indexIter && index < pos) { if (index !== undefined && index > indexIter && index < pos) {
indexIter = index; indexIter = index;
} }
}); });
@@ -174,7 +176,7 @@ export const InfisicalSecretInput = ({
// this is so that we know the limitation for slicing references // this is so that we know the limitation for slicing references
let indexIter = Infinity; let indexIter = Infinity;
unclosedReferenceIndexMatches.forEach((index) => { unclosedReferenceIndexMatches.forEach((index) => {
if (index && index > pos && index < indexIter) { if (index !== undefined && index > pos && index < indexIter) {
indexIter = index; indexIter = index;
} }
}); });