fix: truncate long approval prefixes when rendering (#8734)

Fixes inscrutable multiline approval requests:
<img width="686" height="844" alt="image"
src="https://github.com/user-attachments/assets/cf9493dc-79e6-4168-8020-0ef0fe676d5e"
/>
This commit is contained in:
Thibault Sottiaux
2026-01-06 15:17:01 -08:00
committed by GitHub
parent dc1a568dc7
commit 8b4d27dfcd
6 changed files with 127 additions and 6 deletions

View File

@@ -461,9 +461,13 @@ fn exec_options(
.chain(
proposed_execpolicy_amendment
.filter(|_| features.enabled(Feature::ExecPolicy))
.map(|prefix| {
.and_then(|prefix| {
let rendered_prefix = strip_bash_lc_and_escape(prefix.command());
ApprovalOption {
if rendered_prefix.contains('\n') || rendered_prefix.contains('\r') {
return None;
}
Some(ApprovalOption {
label: format!(
"Yes, and don't ask again for commands that start with `{rendered_prefix}`"
),
@@ -474,7 +478,7 @@ fn exec_options(
),
display_shortcut: None,
additional_shortcuts: vec![key_hint::plain(KeyCode::Char('p'))],
}
})
}),
)
.chain([ApprovalOption {