From 153c98a4572dd70b887853fd2ef7eef165b68985 Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Wed, 4 Nov 2026 04:59:38 -0600 Subject: [PATCH] fix(atlas-search): escape U+007F in pyjson ensure_ascii mode (#5404) --- .../crates/atlas-search/src/pyjson.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkgs/atlas-search/crates/atlas-search/src/pyjson.rs b/pkgs/atlas-search/crates/atlas-search/src/pyjson.rs index 7a7c5a12d5..0821c62628 100644 --- a/pkgs/atlas-search/crates/atlas-search/src/pyjson.rs +++ b/pkgs/atlas-search/crates/atlas-search/src/pyjson.rs @@ -104,7 +104,7 @@ pub fn py_string(s: &str, ensure_ascii: bool) -> String { c if (c as u32) < 0x20 => { let _ = write!(out, "\\u{:04x}", c as u32); } - c if ensure_ascii && (c as u32) > 0x7f => { + c if ensure_ascii && (c as u32) >= 0x7f => { if (c as u32) > 0xffff { let v = (c as u32) - 0x10000; let _ = write!( @@ -257,6 +257,19 @@ mod tests { ); } + #[test] + fn compact_escapes_del_like_cpython() { + // CPython's ensure_ascii encoder escapes everything outside + // 0x20..=0x7e, so DEL (0x7f) becomes \u007f even though it is + // ASCII; with ensure_ascii=False it stays raw (#5404). + assert_eq!(py_string("\u{7f}", true), "\"\\u007f\""); + assert_eq!(py_string("\u{7f}", false), "\"\u{7f}\""); + assert_eq!(py_string("~", true), "\"~\""); + assert_eq!(py_string("\u{80}", true), "\"\\u0080\""); + let v = json!({"k": "x\u{7f}y"}); + assert_eq!(dumps_compact(&v), "{\"k\": \"x\\u007fy\"}"); + } + #[test] fn compact_escapes_non_ascii() { let v = json!({"k": "café"});