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) };