From be3faf0552d60c996aeb51016f93ef64a3dd2d6f Mon Sep 17 00:00:00 2001 From: Jonas Maier Date: Mon, 4 May 2026 23:57:57 +0200 Subject: escape test --- src/parse/mod.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/parse/mod.rs') diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 02012dc..efef937 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -717,12 +717,12 @@ impl StringDelimiter { let first = s[0]; match self { StringDelimiter::None => { - if matches!(first, b' ' | b'$' | b'\\' | b'\'' | b'"') { + if matches!(first, b' ' | b'$' | b'\\' | b'\'' | b'"' | b'|' | b'{' | b'}') { out.push(b'\\'); } } StringDelimiter::Interp | StringDelimiter::InterpCustom(_) => { - if matches!(first, b'$' | b'\\' | b'"') { + if matches!(first, b'$' | b'\\' | b'"' | b'|') { out.push(b'\\'); } } @@ -750,6 +750,22 @@ impl StringDelimiter { } } + pub fn write_opening_delimiter(&self, out: &mut BString) { + match self { + StringDelimiter::None => (), + StringDelimiter::Interp => out.push(b'"'), + StringDelimiter::Strict => out.push(b'\''), + StringDelimiter::InterpCustom(delim) => { + out.push_all(&delim); + out.push_all(b"\"\"\""); + } + StringDelimiter::StrictCustom(delim) => { + out.push_all(&delim); + out.push_all(b"'''"); + } + } + } + pub fn write_closing_delimiter(&self, out: &mut BString) { match self { StringDelimiter::None => (), @@ -841,7 +857,7 @@ impl Parse for ExpString { let x = b.adv(); - if x == b'\\' { + if x == b'\\' && !delim.is_strict() { if let Some(x) = parse_escape_code(b)? { add_char(p, x); } -- cgit v1.2.3