Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/fix-strip-suffix-unwrap.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion src/auth_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/setup_tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&current_label).to_string()
} else {
format!("{}.readonly", current_label)
};
Expand Down
Loading