mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Avoid allocations when sanitizing TUI user text (#38214)
## Why Sanitizing user messages and pasted text always allocated a new string, even when the input contained no terminal control characters. ## What changed - Return a `Cow<str>` from `sanitize_user_text` so clean borrowed input remains borrowed. - Reuse owned input buffers when sanitization leaves the text intact or only removes content at the edges. - Update transcript rendering, history cells, and paste handling to consume the borrowed-or-owned result without unnecessary cloning. ## Testing Add sanitizer coverage for clean text, control sequences, Unicode control characters, incomplete escape sequences, buffer reuse, and multi-fragment output. GitOrigin-RevId: 9e39cbc0d83c5791941b37a7eb4bb918c1a05f68
This commit is contained in:
committed by
copyberry
parent
95aada11c4
commit
91d6f48992
@@ -224,7 +224,7 @@ fn render_markdown_transcript(cells: &[Arc<dyn HistoryCell>]) -> Result<String,
|
||||
let lines = if let Some(user) = cell.as_any().downcast_ref::<UserHistoryCell>() {
|
||||
let (message, _) =
|
||||
crate::ide_context::extract_prompt_request_with_offset(&user.message);
|
||||
let message = crate::history_cell::sanitize_user_text(message);
|
||||
let message = crate::history_cell::sanitize_user_text(message.into());
|
||||
let mut lines = raw_lines_from_source(&message);
|
||||
let image_count = user.local_image_paths.len() + user.remote_image_urls.len();
|
||||
let image_labels = (0..image_count)
|
||||
@@ -273,9 +273,7 @@ fn render_markdown_transcript(cells: &[Arc<dyn HistoryCell>]) -> Result<String,
|
||||
markdown.push_str(" ");
|
||||
}
|
||||
for span in line.spans {
|
||||
markdown.push_str(&crate::history_cell::sanitize_user_text(
|
||||
span.content.as_ref(),
|
||||
));
|
||||
markdown.push_str(&crate::history_cell::sanitize_user_text(span.content));
|
||||
}
|
||||
markdown.push('\n');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user