Skip to content

Commit

Permalink
Add escape for \' (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuataylor committed Aug 30, 2022
1 parent ec09304 commit 2e62775
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion minijinja/src/utils.rs
Expand Up @@ -102,7 +102,7 @@ impl Unescaper {
match char_iter.next() {
None => return Err(ErrorKind::BadEscape.into()),
Some(d) => match d {
'"' | '\\' | '/' => self.push_char(d)?,
'"' | '\\' | '/' | '\'' => self.push_char(d)?,
'b' => self.push_char('\x08')?,
'f' => self.push_char('\x0C')?,
'n' => self.push_char('\n')?,
Expand Down
8 changes: 8 additions & 0 deletions minijinja/tests/inputs/escape.txt
@@ -0,0 +1,8 @@
{
"x": "hello"
}
---
{{'\'' ~ 'foo'}}
{{'\'' ~ x ~ '\''}}
{{"\'" ~ x ~ '\''}}
{{"\'" ~ x ~ '\''}}
3 changes: 3 additions & 0 deletions minijinja/tests/parser-inputs/escape.txt
@@ -0,0 +1,3 @@
{{'\'' ~ 'foo'}}
{{'\'' ~ "foo"}}
{{"\'"}}
44 changes: 44 additions & 0 deletions minijinja/tests/snapshots/test_parser__parser@escape.txt.snap
@@ -0,0 +1,44 @@
---
source: minijinja/tests/test_parser.rs
expression: "&ast"
input_file: minijinja/tests/parser-inputs/escape.txt
---
Ok(
Template {
children: [
EmitExpr {
expr: BinOp {
op: Concat,
left: Const {
value: "'",
} @ 1:2-1:6,
right: Const {
value: "foo",
} @ 1:9-1:14,
} @ 1:0-1:14,
} @ 1:0-1:14,
EmitRaw {
raw: "\n",
} @ 1:16-2:0,
EmitExpr {
expr: BinOp {
op: Concat,
left: Const {
value: "'",
} @ 2:2-2:6,
right: Const {
value: "foo",
} @ 2:9-2:14,
} @ 2:0-2:14,
} @ 2:0-2:14,
EmitRaw {
raw: "\n",
} @ 2:16-3:0,
EmitExpr {
expr: Const {
value: "'",
} @ 3:2-3:6,
} @ 3:0-3:6,
],
} @ 0:0-3:8,
)
10 changes: 10 additions & 0 deletions minijinja/tests/snapshots/test_templates__vm@escape.txt.snap
@@ -0,0 +1,10 @@
---
source: minijinja/tests/test_templates.rs
expression: "&rendered"
input_file: minijinja/tests/inputs/escape.txt
---
'foo
'hello'
'hello'
'hello'

0 comments on commit 2e62775

Please sign in to comment.