From d23ecc9c698a45ba6af7ed13f1b0880b2525bcbe Mon Sep 17 00:00:00 2001 From: Andrew Barnes Date: Thu, 5 Mar 2026 12:34:19 -0500 Subject: [PATCH] fix: replace strip_suffix(".readonly").unwrap() with unwrap_or Two call sites in auth_commands.rs and setup_tui.rs used .strip_suffix(".readonly").unwrap(), which panics if a scope URL flagged as is_readonly doesn't end with ".readonly". Replace with .unwrap_or() to gracefully fall back to the original URL rather than crashing on inconsistent discovery data. --- .changeset/fix-strip-suffix-unwrap.md | 11 +++++++++++ src/auth_commands.rs | 2 +- src/setup_tui.rs | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .changeset/fix-strip-suffix-unwrap.md diff --git a/.changeset/fix-strip-suffix-unwrap.md b/.changeset/fix-strip-suffix-unwrap.md new file mode 100644 index 0000000..fc23ada --- /dev/null +++ b/.changeset/fix-strip-suffix-unwrap.md @@ -0,0 +1,11 @@ +--- +"@anthropic/gws": patch +--- + +Replace strip_suffix(".readonly").unwrap() with unwrap_or fallback + +Two call sites used `.strip_suffix(".readonly").unwrap()` which would +panic if a scope URL marked as `is_readonly` didn't actually end with +".readonly". While the current data makes this unlikely, using +`unwrap_or` is a defensive improvement that prevents potential panics +from inconsistent discovery data. diff --git a/src/auth_commands.rs b/src/auth_commands.rs index b5a5bb8..d5d0b33 100644 --- a/src/auth_commands.rs +++ b/src/auth_commands.rs @@ -754,7 +754,7 @@ fn run_discovery_scope_picker( }; let is_recommended = if entry.is_readonly { - let superset = entry.url.strip_suffix(".readonly").unwrap(); + let superset = entry.url.strip_suffix(".readonly").unwrap_or(&entry.url); let superset_is_recommended = filtered_scopes .iter() .any(|s| s.url == superset && s.classification != ScopeClassification::Restricted); diff --git a/src/setup_tui.rs b/src/setup_tui.rs index d47a3c6..ded985c 100644 --- a/src/setup_tui.rs +++ b/src/setup_tui.rs @@ -184,7 +184,7 @@ impl PickerState { // Only deselect the counterpart when we are SELECTING an item if current_selected { let counterpart_to_deselect = if current_label.ends_with(".readonly") { - current_label.strip_suffix(".readonly").unwrap().to_string() + current_label.strip_suffix(".readonly").unwrap_or(¤t_label).to_string() } else { format!("{}.readonly", current_label) };