mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
simplify exec config summary sanitization
This commit is contained in:
@@ -418,50 +418,24 @@ impl EventProcessor for EventProcessorWithHumanOutput {
|
||||
}
|
||||
|
||||
fn sanitize_config_summary_value(value: &str) -> String {
|
||||
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
|
||||
}
|
||||
|
||||
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}'
|
||||
)
|
||||
value
|
||||
.chars()
|
||||
.map(|ch| {
|
||||
if ch.is_control()
|
||||
|| matches!(
|
||||
ch,
|
||||
'\u{061C}'
|
||||
| '\u{200E}'..='\u{200F}'
|
||||
| '\u{202A}'..='\u{202E}'
|
||||
| '\u{2066}'..='\u{2069}'
|
||||
)
|
||||
{
|
||||
'�'
|
||||
} else {
|
||||
ch
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn config_summary_entries(
|
||||
|
||||
@@ -178,10 +178,8 @@ fn summarizes_managed_read_only_permission_profile() {
|
||||
#[test]
|
||||
fn config_summary_values_are_single_line_terminal_text() {
|
||||
assert_eq!(
|
||||
sanitize_config_summary_value(
|
||||
" repo\t|\nWorking\x1b\u{0007}\u{009D}\u{009C} | \u{202E}T\u{2066}ext "
|
||||
),
|
||||
"repo | Working | Text"
|
||||
sanitize_config_summary_value("repo\nmodel: other\r\x1b[2J\u{0007}\u{202E}rtl\u{2066}"),
|
||||
"repo�model: other��[2J��rtl�"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user