From f3787ef305706779205d811cbe0840dcf6136ad2 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 26 Jan 2020 16:28:38 -0500 Subject: [PATCH] Escape double quotes --- src/value.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/value.rs b/src/value.rs index a12e6d3..1b473cd 100644 --- a/src/value.rs +++ b/src/value.rs @@ -279,9 +279,16 @@ impl Value { } TokenKind::Symbol(Symbol::DoubleQuote) => { let mut s = String::new(); + let mut is_escaped = false; while let Some(tok) = toks.next() { - if tok.kind == TokenKind::Symbol(Symbol::DoubleQuote) { - break; + match tok.kind { + TokenKind::Symbol(Symbol::DoubleQuote) if !is_escaped => break, + TokenKind::Symbol(Symbol::BackSlash) if !is_escaped => is_escaped = true, + TokenKind::Symbol(Symbol::BackSlash) => s.push('\\'), + _ => {} + } + if is_escaped && tok.kind != TokenKind::Symbol(Symbol::BackSlash) { + is_escaped = false; } s.push_str(&tok.kind.to_string()); }