mirror of
https://github.com/openai/codex.git
synced 2026-10-29 19:08:43 +00:00
tighten exec config summary sanitization
This commit is contained in:
@@ -419,10 +419,51 @@ impl EventProcessor for EventProcessorWithHumanOutput {
|
||||
|
||||
/// Converts a config-summary value into printable single-line terminal text.
|
||||
fn sanitize_config_summary_value(value: &str) -> String {
|
||||
value
|
||||
.chars()
|
||||
.map(|ch| if ch.is_control() { '�' } else { ch })
|
||||
.collect()
|
||||
let mut sanitized = String::new();
|
||||
let mut pending_space = false;
|
||||
|
||||
for ch in value.chars() {
|
||||
if ch.is_whitespace() {
|
||||
pending_space = !sanitized.is_empty();
|
||||
continue;
|
||||
}
|
||||
|
||||
if is_disallowed_config_summary_char(ch) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if pending_space {
|
||||
sanitized.push(' ');
|
||||
pending_space = false;
|
||||
}
|
||||
|
||||
sanitized.push(ch);
|
||||
}
|
||||
|
||||
sanitized
|
||||
}
|
||||
|
||||
/// Returns whether `ch` should be dropped from config-summary output.
|
||||
fn is_disallowed_config_summary_char(ch: char) -> bool {
|
||||
if ch.is_control() {
|
||||
return true;
|
||||
}
|
||||
|
||||
matches!(
|
||||
ch,
|
||||
'\u{00AD}'
|
||||
| '\u{034F}'
|
||||
| '\u{061C}'
|
||||
| '\u{180E}'
|
||||
| '\u{200B}'..='\u{200F}'
|
||||
| '\u{202A}'..='\u{202E}'
|
||||
| '\u{2060}'..='\u{206F}'
|
||||
| '\u{FE00}'..='\u{FE0F}'
|
||||
| '\u{FEFF}'
|
||||
| '\u{FFF9}'..='\u{FFFB}'
|
||||
| '\u{1BCA0}'..='\u{1BCA3}'
|
||||
| '\u{E0100}'..='\u{E01EF}'
|
||||
)
|
||||
}
|
||||
|
||||
fn config_summary_entries(
|
||||
|
||||
@@ -178,8 +178,10 @@ fn summarizes_managed_read_only_permission_profile() {
|
||||
#[test]
|
||||
fn config_summary_values_are_single_line_terminal_text() {
|
||||
assert_eq!(
|
||||
sanitize_config_summary_value("repo\nmodel: other\r\x1b[2J\u{0007}"),
|
||||
"repo�model: other��[2J�"
|
||||
sanitize_config_summary_value(
|
||||
" repo\t|\nWorking\x1b\u{0007}\u{009D}\u{009C} | \u{202E}T\u{2066}ext "
|
||||
),
|
||||
"repo | Working | Text"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user