-
-
Notifications
You must be signed in to change notification settings - Fork 414
Open
Labels
Description
Problem Description
Critical bugs identified in PR #1011 (help menu search functionality) that need immediate attention:
1. CRITICAL: Bounds Access Panic Risk
Location: src/internal/handle_modal.go lines 149 and 153 in helpMenuListUp()
Issue: Direct slice access without bounds validation:
if m.helpMenu.filteredData[m.helpMenu.cursor].subTitle != "" { // Line 149 - PANIC RISK
m.helpMenu.renderIndex--
}
if m.helpMenu.filteredData[m.helpMenu.cursor].subTitle != "" { // Line 153 - PANIC RISK
m.helpMenu.cursor--
}Impact: Application crash when filteredData is empty or cursor is out of bounds.
2. SEVERE: Performance Degradation
Issues:
- Multiple
len(m.helpMenu.filteredData)calls (6+ times per navigation) - Rendering recalculates key lengths on every frame
- No input debouncing for rapid typing
- Redundant calculations in render loop
3. Race Conditions (Future Consideration)
Navigation functions perform multiple operations on filteredData without atomic checks. While not currently an issue due to no concurrent access, should be considered for future improvements.
Required Fixes
Immediate (Critical):
- Add bounds checking before all slice access operations:
func (m *model) helpMenuListUp() {
if len(m.helpMenu.filteredData) == 0 {
return
}
if m.helpMenu.cursor < 0 || m.helpMenu.cursor >= len(m.helpMenu.filteredData) {
m.helpMenu.cursor = 1 // Reset to safe position
return
}
// ... rest with safe access
}- Cache length calculations to avoid repeated calls
- Add state validation to ensure cursor/renderIndex consistency
Unit Testing Coverage Needed:
TestHelpMenuListUpEmptyDataTestHelpMenuListDownEmptyDataTestHelpMenuNavigationWithInvalidCursorTestFuzzySearchEmptyInputTestFuzzySearchSpecialCharactersTestRemoveOrphanSectionsAllRemovedTestFilterHelpMenuStateConsistencyTestSearchBarFocusTransitions
Manual Testing Requirements
- Search queries that match nothing
- Navigate in empty filtered results
- Rapid type/delete in search bar
- Navigate while typing
- Resize terminal during search
References
- PR: feat: Add search functionality to help menu (#1009) #1011
- Review comment: feat: Add search functionality to help menu (#1009) #1011 (comment)
- Requested by: @lazysegtree