Skip to content

fix(rice-switch): cancel on Esc instead of switching and logging out - #76

Merged
Schnee111 merged 1 commit into
mainfrom
fix/issue-74-rice-switch-esc
Oct 25, 2026
Merged

Schnee111 merged 1 commit into
mainfrom
fix/issue-74-rice-switch-esc

Conversation

@Schnee111

Copy link
Copy Markdown
Owner

Fixes #74

What this fixes

Pressing Esc in the rice switcher menu switched and logged out instead of cancelling. gui_menu runs in ACTION="$(gui_menu)", so its exit 0 on cancel left only the subshell and ACTION came back empty. Then switch_to "" went on:

  1. rices/ passed the directory check;
  2. install.sh --rice "" relinked the current rice;
  3. an empty .current_rice was written;
  4. the session logged out.

Approach

  • Right after gui_menu, an empty ACTION exits 0. That covers Esc, a closed menu and a row that matches nothing.
  • switch_to accepts only names matching ^[A-Za-z0-9][A-Za-z0-9._-]*$. An empty or path-like name (../end4, ., -x) now fails with Invalid rice name instead of resolving to rices/ or outside it. status and list are handled before this check, so they are unchanged.
  • New tests/rice-switch.sh runs every case with --dry-run and a stub rofi:
    • Esc (exit 1) and an empty choice (exit 0, no output) both exit 0 and print nothing;
    • a chosen row still reaches the switch;
    • four invalid names are rejected.

Verification

  • bash tests/run.sh: all test files pass. shellcheck reports no new findings; the SC2015 info at line 146 is from before this change.
  • Negative control: with bin/rice-switch from main, the test fails with esc: expected no output, the switch ran: rice-switch: dry run for '' ....

Risk

Low. Only the cancel path and invalid names behave differently. Every name under rices/ matches the pattern.

gui_menu runs in a command substitution, so its `exit 0` on Esc only left
the subshell. ACTION was empty and switch_to "" went on: rices/ passed
the directory check, install.sh relinked the current rice, an empty
.current_rice was written and the session logged out. Stop when nothing
was chosen, and reject empty or path-like rice names in switch_to.

Fixes #74
Copilot AI balanced review requested due to automatic review settings October 25, 2026 00:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@Schnee111 Schnee111 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autonomous Code Review

Verdict: Approved
Target Commit: 217a600

Summary

Effectively fixes the session logout and rice state corruption when cancelling the menu by exiting early on empty selections and validating rice names against path traversal.


Shorekeeper Sentinel · Autonomous Quality Gate

@Schnee111
Schnee111 merged commit eaf6e08 into main Oct 25, 2026
1 check passed
@Schnee111
Schnee111 deleted the fix/issue-74-rice-switch-esc branch October 25, 2026 00:33
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

Successfully merging this pull request may close these issues.

rice-switch: Esc in the menu switches and logs out instead of cancelling

2 participants