debugger: Reverse Python repr escaping (#50554)

Closes #37168

Authored-By: @ngauder

Release Notes:

- debugger: Unescape Python strings

Co-authored-by: Nikolas Gauder <nikolas.gauder@tum.de>
This commit is contained in:
Conrad Irwin 2026-03-04 12:55:20 -07:00 committed by GitHub
parent 5c91ebf1fe
commit 0fc5bc2e89
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2645,10 +2645,40 @@ impl Session {
self.fetch(
command,
move |this, variables, cx| {
let Some(variables) = variables.log_err() else {
let Some(mut variables) = variables.log_err() else {
return;
};
if this.adapter.0.as_ref() == "Debugpy" {
for variable in variables.iter_mut() {
if variable.type_ == Some("str".into()) {
// reverse Python repr() escaping
let mut unescaped = String::with_capacity(variable.value.len());
let mut chars = variable.value.chars();
while let Some(c) = chars.next() {
if c != '\\' {
unescaped.push(c);
} else {
match chars.next() {
Some('\\') => unescaped.push('\\'),
Some('n') => unescaped.push('\n'),
Some('t') => unescaped.push('\t'),
Some('r') => unescaped.push('\r'),
Some('\'') => unescaped.push('\''),
Some('"') => unescaped.push('"'),
Some(c) => {
unescaped.push('\\');
unescaped.push(c);
}
None => {}
}
}
}
variable.value = unescaped;
}
}
}
this.active_snapshot
.variables
.insert(variables_reference, variables);