From 3568a472353f34a59c3592faa4f0b8d83321c8d3 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 17 Oct 2023 23:21:56 +0200 Subject: [PATCH] Fix string octal escape encoding The bug affected invisible ASCII characters that have one of the two high bits set, so only DEL. --- src/buf.rs | 2 +- src/object.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/buf.rs b/src/buf.rs index c3fceca..b6bf397 100644 --- a/src/buf.rs +++ b/src/buf.rs @@ -76,7 +76,7 @@ impl BufExt for Vec { } self.push(octal(value >> 6)); - self.push(octal((value >> 3) & 63)); + self.push(octal((value >> 3) & 7)); self.push(octal(value & 7)); } } diff --git a/src/object.rs b/src/object.rs index d0cf5e8..5445079 100644 --- a/src/object.rs +++ b/src/object.rs @@ -1088,6 +1088,7 @@ mod tests { test_primitive!(Str(br"\n"), br"(\\n)"); test_primitive!(Str(b"a\x14b"), br"(a\024b)"); test_primitive!(Str(b"\xFF\xAA"), b""); + test_primitive!(Str(b"\x0A\x7F\x1F"), br"(\n\177\037)"); // Test text strings. test_primitive!(TextStr("Hallo"), b"(Hallo)");