From 377fbf4889c9d867a5b651740a56cbda2a7c1458 Mon Sep 17 00:00:00 2001 From: Joshua Barr Date: Tue, 21 Jan 2025 18:25:59 -0800 Subject: [PATCH] Don't escape / in pretty-printed strings Fixes #900 --- ion-tests | 2 +- src/text/text_formatter.rs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ion-tests b/ion-tests index 8d18f2f6..9d73a411 160000 --- a/ion-tests +++ b/ion-tests @@ -1 +1 @@ -Subproject commit 8d18f2f66aa7bd43149fe8f11965c1135d39c476 +Subproject commit 9d73a4112a7754b392adede62d6a20bc219a036b diff --git a/src/text/text_formatter.rs b/src/text/text_formatter.rs index 38a10338..b3ced99a 100644 --- a/src/text/text_formatter.rs +++ b/src/text/text_formatter.rs @@ -315,10 +315,8 @@ impl FmtValueFormatter<'_, W> { '\r' => r"\r", '\t' => r"\t", '\\' => r"\\", - '/' => r"\/", '"' => r#"\""#, '\'' => r"\'", - '?' => r"\?", '\x00' => r"\0", // NUL '\x07' => r"\a", // alert BEL '\x08' => r"\b", // backspace @@ -577,6 +575,16 @@ mod formatter_test { #[test] fn test_format_string() -> IonResult<()> { formatter(|ivf| ivf.format_string("bar"), "\"bar\""); + + // Test some string escapes + formatter(|ivf| ivf.format_string("/"), "\"/\""); // slash is not escaped + formatter(|ivf| ivf.format_string("\\"), "\"\\\\\""); // backslash is escaped + formatter(|ivf| ivf.format_string("'"), "\"\\'\""); // single quote is escaped + formatter(|ivf| ivf.format_string("\n"), "\"\\n\""); // newline is escaped + formatter(|ivf| ivf.format_string("\r"), "\"\\r\""); // carriage return is escaped + formatter(|ivf| ivf.format_string("\t"), "\"\\t\""); // tab is escaped + formatter(|ivf| ivf.format_string("\0"), "\"\\0\""); // NUL is escaped + Ok(()) }