@@ -23,11 +23,12 @@ pub fn raw_block(_tag_name: &str,
2323 _options : & LiquidOptions )
2424 -> Result < Box < Renderable > > {
2525 let content = tokens. iter ( ) . fold ( "" . to_owned ( ) , |a, b| {
26+ a +
2627 match * b {
2728 Element :: Expression ( _, ref text) |
2829 Element :: Tag ( _, ref text) |
2930 Element :: Raw ( ref text) => text,
30- } . to_owned ( ) + & a
31+ }
3132 } ) ;
3233 Ok ( Box :: new ( RawT { content : content } ) )
3334}
@@ -36,6 +37,7 @@ pub fn raw_block(_tag_name: &str,
3637mod test {
3738 use super :: * ;
3839 use compiler;
40+ use interpreter;
3941
4042 fn options ( ) -> LiquidOptions {
4143 let mut options = LiquidOptions :: default ( ) ;
@@ -45,7 +47,7 @@ mod test {
4547 }
4648
4749 #[ test]
48- fn test_raw ( ) {
50+ fn raw_text ( ) {
4951 let raw = raw_block ( "raw" ,
5052 & [ ] ,
5153 & vec ! [ Element :: Expression ( vec![ ] , "This is a test" . to_owned( ) ) ] ,
@@ -54,4 +56,32 @@ mod test {
5456 let output = raw. render ( & mut Default :: default ( ) ) . unwrap ( ) ;
5557 assert_eq ! ( output, Some ( "This is a test" . to_owned( ) ) ) ;
5658 }
59+
60+ #[ test]
61+ fn raw_escaped ( ) {
62+ let text = "{%raw%}{%if%}{%endraw%}" ;
63+
64+ let tokens = compiler:: tokenize ( & text) . unwrap ( ) ;
65+ let template = compiler:: parse ( & tokens, & options ( ) )
66+ . map ( interpreter:: Template :: new)
67+ . unwrap ( ) ;
68+
69+ let mut context = Context :: new ( ) ;
70+ let output = template. render ( & mut context) . unwrap ( ) ;
71+ assert_eq ! ( output, Some ( "{%if%}" . to_owned( ) ) ) ;
72+ }
73+
74+ #[ test]
75+ fn raw_mixed ( ) {
76+ let text = "{%raw%}hello{%if%}world{%endraw%}" ;
77+
78+ let tokens = compiler:: tokenize ( & text) . unwrap ( ) ;
79+ let template = compiler:: parse ( & tokens, & options ( ) )
80+ . map ( interpreter:: Template :: new)
81+ . unwrap ( ) ;
82+
83+ let mut context = Context :: new ( ) ;
84+ let output = template. render ( & mut context) . unwrap ( ) ;
85+ assert_eq ! ( output, Some ( "hello{%if%}world" . to_owned( ) ) ) ;
86+ }
5787}
0 commit comments