From c93e08f4a7626b906e100ee86a2e8189a6159c12 Mon Sep 17 00:00:00 2001 From: Ron Klinkien Date: Sat, 12 Sep 2026 15:28:57 +0200 Subject: [PATCH] fix: stop demo.py's menu dispatch from needing a hardcoded key whitelist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Selecting a category option checked the pressed key against a literal "0123456789abc...xyzA" string before ever looking at the category's own options dict. Every time a new uppercase option key got added to menu_categories (most recently [B] for get_next_scheduled_workout) that string had to be remembered and updated too, or the option is unreachable — pressing B printed "Invalid selection" even though it's a real, listed menu entry. Drop the whitelist. The options dict membership check right below it already does the real validation correctly by construction, and its "Invalid option selection" message already lists the real valid keys for the current category, so nothing is lost — the whole bug class becomes impossible instead of one whitelist edit behind every new key. --- demo.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/demo.py b/demo.py index 7d7cb39d..5819e3da 100755 --- a/demo.py +++ b/demo.py @@ -5173,10 +5173,14 @@ def main(): print_category_menu(current_category) option = safe_readkey() - # Handle category menu options + # Handle category menu options. Validity is decided solely by + # membership in the current category's own options dict — + # no separate hardcoded character whitelist to keep in sync + # whenever a new option key (e.g. an uppercase letter) is + # added to menu_categories. if option == "q": current_category = None # Back to main menu - elif option in "0123456789abcdefghijklmnopqrstuvwxyzA": + else: try: category_data = menu_categories[current_category] category_options = category_data["options"] @@ -5190,10 +5194,6 @@ def main(): ) except Exception as e: print(f"❌ Error processing option {option}: {e}") - else: - print( - "❌ Invalid selection. Use numbers/letters for options or 'q' to go back/quit" - ) except KeyboardInterrupt: print("\nInterrupted by user. Press q to quit.")