Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

agent: Add XML escaping for TextThreadContext title attribute (#39734)

Xiaobo Liud7b7fa3ee22d
diff --git a/crates/agent_ui/src/context.rs b/crates/agent_ui/src/context.rs
index 2a1ff4a1d9d..022f4e4d2ff 100644
--- a/crates/agent_ui/src/context.rs
+++ b/crates/agent_ui/src/context.rs
@@ -620,8 +620,18 @@ impl TextThreadContextHandle {
impl Display for TextThreadContext {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
- // TODO: escape title?
- writeln!(f, "<text_thread title=\"{}\">", self.title)?;
+ write!(f, "<text_thread title=\"")?;
+ for c in self.title.chars() {
+ match c {
+ '&' => write!(f, "&amp;")?,
+ '<' => write!(f, "&lt;")?,
+ '>' => write!(f, "&gt;")?,
+ '"' => write!(f, "&quot;")?,
+ '\'' => write!(f, "&apos;")?,
+ _ => write!(f, "{}", c)?,
+ }
+ }
+ writeln!(f, "\">")?;
write!(f, "{}", self.text.trim())?;
write!(f, "\n</text_thread>")
}