Skip to content

Commit

Permalink
Don't escape / in pretty-printed strings
Browse files Browse the repository at this point in the history
Fixes #900
  • Loading branch information
jobarr-amzn committed Jan 22, 2025
1 parent 53561b4 commit 377fbf4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/text/text_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,8 @@ impl<W: fmt::Write> 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
Expand Down Expand Up @@ -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(())
}

Expand Down

0 comments on commit 377fbf4

Please sign in to comment.