liquid 2.6.3 → 5.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +5 -5
  2. data/History.md +272 -26
  3. data/README.md +67 -3
  4. data/lib/liquid/block.rb +62 -94
  5. data/lib/liquid/block_body.rb +255 -0
  6. data/lib/liquid/condition.rb +96 -38
  7. data/lib/liquid/context.rb +172 -154
  8. data/lib/liquid/document.rb +57 -9
  9. data/lib/liquid/drop.rb +33 -14
  10. data/lib/liquid/errors.rb +56 -10
  11. data/lib/liquid/expression.rb +45 -0
  12. data/lib/liquid/extensions.rb +21 -7
  13. data/lib/liquid/file_system.rb +27 -14
  14. data/lib/liquid/forloop_drop.rb +92 -0
  15. data/lib/liquid/i18n.rb +41 -0
  16. data/lib/liquid/interrupts.rb +3 -2
  17. data/lib/liquid/lexer.rb +62 -0
  18. data/lib/liquid/locales/en.yml +29 -0
  19. data/lib/liquid/parse_context.rb +54 -0
  20. data/lib/liquid/parse_tree_visitor.rb +42 -0
  21. data/lib/liquid/parser.rb +102 -0
  22. data/lib/liquid/parser_switching.rb +45 -0
  23. data/lib/liquid/partial_cache.rb +24 -0
  24. data/lib/liquid/profiler/hooks.rb +35 -0
  25. data/lib/liquid/profiler.rb +139 -0
  26. data/lib/liquid/range_lookup.rb +47 -0
  27. data/lib/liquid/registers.rb +51 -0
  28. data/lib/liquid/resource_limits.rb +62 -0
  29. data/lib/liquid/standardfilters.rb +789 -118
  30. data/lib/liquid/strainer_factory.rb +41 -0
  31. data/lib/liquid/strainer_template.rb +62 -0
  32. data/lib/liquid/tablerowloop_drop.rb +121 -0
  33. data/lib/liquid/tag/disableable.rb +22 -0
  34. data/lib/liquid/tag/disabler.rb +21 -0
  35. data/lib/liquid/tag.rb +49 -10
  36. data/lib/liquid/tags/assign.rb +61 -19
  37. data/lib/liquid/tags/break.rb +14 -4
  38. data/lib/liquid/tags/capture.rb +29 -21
  39. data/lib/liquid/tags/case.rb +80 -31
  40. data/lib/liquid/tags/comment.rb +24 -2
  41. data/lib/liquid/tags/continue.rb +14 -13
  42. data/lib/liquid/tags/cycle.rb +50 -32
  43. data/lib/liquid/tags/decrement.rb +24 -26
  44. data/lib/liquid/tags/echo.rb +41 -0
  45. data/lib/liquid/tags/for.rb +164 -100
  46. data/lib/liquid/tags/if.rb +105 -44
  47. data/lib/liquid/tags/ifchanged.rb +10 -11
  48. data/lib/liquid/tags/include.rb +85 -65
  49. data/lib/liquid/tags/increment.rb +24 -22
  50. data/lib/liquid/tags/inline_comment.rb +43 -0
  51. data/lib/liquid/tags/raw.rb +50 -11
  52. data/lib/liquid/tags/render.rb +109 -0
  53. data/lib/liquid/tags/table_row.rb +88 -0
  54. data/lib/liquid/tags/unless.rb +37 -21
  55. data/lib/liquid/template.rb +124 -46
  56. data/lib/liquid/template_factory.rb +9 -0
  57. data/lib/liquid/tokenizer.rb +39 -0
  58. data/lib/liquid/usage.rb +8 -0
  59. data/lib/liquid/utils.rb +68 -5
  60. data/lib/liquid/variable.rb +128 -32
  61. data/lib/liquid/variable_lookup.rb +96 -0
  62. data/lib/liquid/version.rb +3 -1
  63. data/lib/liquid.rb +36 -13
  64. metadata +69 -77
  65. data/lib/extras/liquid_view.rb +0 -51
  66. data/lib/liquid/htmltags.rb +0 -73
  67. data/lib/liquid/module_ex.rb +0 -62
  68. data/lib/liquid/strainer.rb +0 -53
  69. data/test/liquid/assign_test.rb +0 -21
  70. data/test/liquid/block_test.rb +0 -58
  71. data/test/liquid/capture_test.rb +0 -40
  72. data/test/liquid/condition_test.rb +0 -127
  73. data/test/liquid/context_test.rb +0 -478
  74. data/test/liquid/drop_test.rb +0 -180
  75. data/test/liquid/error_handling_test.rb +0 -81
  76. data/test/liquid/file_system_test.rb +0 -29
  77. data/test/liquid/filter_test.rb +0 -125
  78. data/test/liquid/hash_ordering_test.rb +0 -25
  79. data/test/liquid/module_ex_test.rb +0 -87
  80. data/test/liquid/output_test.rb +0 -116
  81. data/test/liquid/parsing_quirks_test.rb +0 -52
  82. data/test/liquid/regexp_test.rb +0 -44
  83. data/test/liquid/security_test.rb +0 -64
  84. data/test/liquid/standard_filter_test.rb +0 -263
  85. data/test/liquid/strainer_test.rb +0 -52
  86. data/test/liquid/tags/break_tag_test.rb +0 -16
  87. data/test/liquid/tags/continue_tag_test.rb +0 -16
  88. data/test/liquid/tags/for_tag_test.rb +0 -297
  89. data/test/liquid/tags/html_tag_test.rb +0 -63
  90. data/test/liquid/tags/if_else_tag_test.rb +0 -166
  91. data/test/liquid/tags/include_tag_test.rb +0 -166
  92. data/test/liquid/tags/increment_tag_test.rb +0 -24
  93. data/test/liquid/tags/raw_tag_test.rb +0 -24
  94. data/test/liquid/tags/standard_tag_test.rb +0 -295
  95. data/test/liquid/tags/statements_test.rb +0 -134
  96. data/test/liquid/tags/unless_else_tag_test.rb +0 -26
  97. data/test/liquid/template_test.rb +0 -146
  98. data/test/liquid/variable_test.rb +0 -186
  99. data/test/test_helper.rb +0 -29
  100. /data/{MIT-LICENSE → LICENSE} +0 -0
@@ -1,81 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ErrorDrop < Liquid::Drop
4
- def standard_error
5
- raise Liquid::StandardError, 'standard error'
6
- end
7
-
8
- def argument_error
9
- raise Liquid::ArgumentError, 'argument error'
10
- end
11
-
12
- def syntax_error
13
- raise Liquid::SyntaxError, 'syntax error'
14
- end
15
-
16
- def exception
17
- raise Exception, 'exception'
18
- end
19
-
20
- end
21
-
22
- class ErrorHandlingTest < Test::Unit::TestCase
23
- include Liquid
24
-
25
- def test_standard_error
26
- assert_nothing_raised do
27
- template = Liquid::Template.parse( ' {{ errors.standard_error }} ' )
28
- assert_equal ' Liquid error: standard error ', template.render('errors' => ErrorDrop.new)
29
-
30
- assert_equal 1, template.errors.size
31
- assert_equal StandardError, template.errors.first.class
32
- end
33
- end
34
-
35
- def test_syntax
36
-
37
- assert_nothing_raised do
38
-
39
- template = Liquid::Template.parse( ' {{ errors.syntax_error }} ' )
40
- assert_equal ' Liquid syntax error: syntax error ', template.render('errors' => ErrorDrop.new)
41
-
42
- assert_equal 1, template.errors.size
43
- assert_equal SyntaxError, template.errors.first.class
44
-
45
- end
46
- end
47
-
48
- def test_argument
49
- assert_nothing_raised do
50
-
51
- template = Liquid::Template.parse( ' {{ errors.argument_error }} ' )
52
- assert_equal ' Liquid error: argument error ', template.render('errors' => ErrorDrop.new)
53
-
54
- assert_equal 1, template.errors.size
55
- assert_equal ArgumentError, template.errors.first.class
56
- end
57
- end
58
-
59
- def test_missing_endtag_parse_time_error
60
- assert_raise(Liquid::SyntaxError) do
61
- template = Liquid::Template.parse(' {% for a in b %} ... ')
62
- end
63
- end
64
-
65
- def test_unrecognized_operator
66
- assert_nothing_raised do
67
- template = Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ')
68
- assert_equal ' Liquid error: Unknown operator =! ', template.render
69
- assert_equal 1, template.errors.size
70
- assert_equal Liquid::ArgumentError, template.errors.first.class
71
- end
72
- end
73
-
74
- # Liquid should not catch Exceptions that are not subclasses of StandardError, like Interrupt and NoMemoryError
75
- def test_exceptions_propagate
76
- assert_raise Exception do
77
- template = Liquid::Template.parse( ' {{ errors.exception }} ' )
78
- template.render('errors' => ErrorDrop.new)
79
- end
80
- end
81
- end # ErrorHandlingTest
@@ -1,29 +0,0 @@
1
- require 'test_helper'
2
-
3
- class FileSystemTest < Test::Unit::TestCase
4
- include Liquid
5
-
6
- def test_default
7
- assert_raise(FileSystemError) do
8
- BlankFileSystem.new.read_template_file("dummy", {'dummy'=>'smarty'})
9
- end
10
- end
11
-
12
- def test_local
13
- file_system = Liquid::LocalFileSystem.new("/some/path")
14
- assert_equal "/some/path/_mypartial.liquid" , file_system.full_path("mypartial")
15
- assert_equal "/some/path/dir/_mypartial.liquid", file_system.full_path("dir/mypartial")
16
-
17
- assert_raise(FileSystemError) do
18
- file_system.full_path("../dir/mypartial")
19
- end
20
-
21
- assert_raise(FileSystemError) do
22
- file_system.full_path("/dir/../../dir/mypartial")
23
- end
24
-
25
- assert_raise(FileSystemError) do
26
- file_system.full_path("/etc/passwd")
27
- end
28
- end
29
- end # FileSystemTest
@@ -1,125 +0,0 @@
1
- require 'test_helper'
2
-
3
- module MoneyFilter
4
- def money(input)
5
- sprintf(' %d$ ', input)
6
- end
7
-
8
- def money_with_underscore(input)
9
- sprintf(' %d$ ', input)
10
- end
11
- end
12
-
13
- module CanadianMoneyFilter
14
- def money(input)
15
- sprintf(' %d$ CAD ', input)
16
- end
17
- end
18
-
19
- module SubstituteFilter
20
- def substitute(input, params={})
21
- input.gsub(/%\{(\w+)\}/) { |match| params[$1] }
22
- end
23
- end
24
-
25
- class FiltersTest < Test::Unit::TestCase
26
- include Liquid
27
-
28
- def setup
29
- @context = Context.new
30
- end
31
-
32
- def test_local_filter
33
- @context['var'] = 1000
34
- @context.add_filters(MoneyFilter)
35
-
36
- assert_equal ' 1000$ ', Variable.new("var | money").render(@context)
37
- end
38
-
39
- def test_underscore_in_filter_name
40
- @context['var'] = 1000
41
- @context.add_filters(MoneyFilter)
42
- assert_equal ' 1000$ ', Variable.new("var | money_with_underscore").render(@context)
43
- end
44
-
45
- def test_second_filter_overwrites_first
46
- @context['var'] = 1000
47
- @context.add_filters(MoneyFilter)
48
- @context.add_filters(CanadianMoneyFilter)
49
-
50
- assert_equal ' 1000$ CAD ', Variable.new("var | money").render(@context)
51
- end
52
-
53
- def test_size
54
- @context['var'] = 'abcd'
55
- @context.add_filters(MoneyFilter)
56
-
57
- assert_equal 4, Variable.new("var | size").render(@context)
58
- end
59
-
60
- def test_join
61
- @context['var'] = [1,2,3,4]
62
-
63
- assert_equal "1 2 3 4", Variable.new("var | join").render(@context)
64
- end
65
-
66
- def test_sort
67
- @context['value'] = 3
68
- @context['numbers'] = [2,1,4,3]
69
- @context['words'] = ['expected', 'as', 'alphabetic']
70
- @context['arrays'] = [['flattened'], ['are']]
71
-
72
- assert_equal [1,2,3,4], Variable.new("numbers | sort").render(@context)
73
- assert_equal ['alphabetic', 'as', 'expected'], Variable.new("words | sort").render(@context)
74
- assert_equal [3], Variable.new("value | sort").render(@context)
75
- assert_equal ['are', 'flattened'], Variable.new("arrays | sort").render(@context)
76
- end
77
-
78
- def test_strip_html
79
- @context['var'] = "<b>bla blub</a>"
80
-
81
- assert_equal "bla blub", Variable.new("var | strip_html").render(@context)
82
- end
83
-
84
- def test_strip_html_ignore_comments_with_html
85
- @context['var'] = "<!-- split and some <ul> tag --><b>bla blub</a>"
86
-
87
- assert_equal "bla blub", Variable.new("var | strip_html").render(@context)
88
- end
89
-
90
- def test_capitalize
91
- @context['var'] = "blub"
92
-
93
- assert_equal "Blub", Variable.new("var | capitalize").render(@context)
94
- end
95
-
96
- def test_nonexistent_filter_is_ignored
97
- @context['var'] = 1000
98
-
99
- assert_equal 1000, Variable.new("var | xyzzy").render(@context)
100
- end
101
-
102
- def test_filter_with_keyword_arguments
103
- @context['surname'] = 'john'
104
- @context.add_filters(SubstituteFilter)
105
- output = Variable.new(%! 'hello %{first_name}, %{last_name}' | substitute: first_name: surname, last_name: 'doe' !).render(@context)
106
- assert_equal 'hello john, doe', output
107
- end
108
- end
109
-
110
- class FiltersInTemplate < Test::Unit::TestCase
111
- include Liquid
112
-
113
- def test_local_global
114
- Template.register_filter(MoneyFilter)
115
-
116
- assert_equal " 1000$ ", Template.parse("{{1000 | money}}").render(nil, nil)
117
- assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, :filters => CanadianMoneyFilter)
118
- assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, :filters => [CanadianMoneyFilter])
119
- end
120
-
121
- def test_local_filter_with_deprecated_syntax
122
- assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, CanadianMoneyFilter)
123
- assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, [CanadianMoneyFilter])
124
- end
125
- end # FiltersTest
@@ -1,25 +0,0 @@
1
- require 'test_helper'
2
-
3
- module MoneyFilter
4
- def money(input)
5
- sprintf(' %d$ ', input)
6
- end
7
- end
8
-
9
- module CanadianMoneyFilter
10
- def money(input)
11
- sprintf(' %d$ CAD ', input)
12
- end
13
- end
14
-
15
- class HashOrderingTest < Test::Unit::TestCase
16
- include Liquid
17
-
18
- def test_global_register_order
19
- Template.register_filter(MoneyFilter)
20
- Template.register_filter(CanadianMoneyFilter)
21
-
22
- assert_equal " 1000$ CAD ", Template.parse("{{1000 | money}}").render(nil, nil)
23
- end
24
-
25
- end
@@ -1,87 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestClassA
4
- liquid_methods :allowedA, :chainedB
5
- def allowedA
6
- 'allowedA'
7
- end
8
- def restrictedA
9
- 'restrictedA'
10
- end
11
- def chainedB
12
- TestClassB.new
13
- end
14
- end
15
-
16
- class TestClassB
17
- liquid_methods :allowedB, :chainedC
18
- def allowedB
19
- 'allowedB'
20
- end
21
- def chainedC
22
- TestClassC.new
23
- end
24
- end
25
-
26
- class TestClassC
27
- liquid_methods :allowedC
28
- def allowedC
29
- 'allowedC'
30
- end
31
- end
32
-
33
- class TestClassC::LiquidDropClass
34
- def another_allowedC
35
- 'another_allowedC'
36
- end
37
- end
38
-
39
- class ModuleExTest < Test::Unit::TestCase
40
- include Liquid
41
-
42
- def setup
43
- @a = TestClassA.new
44
- @b = TestClassB.new
45
- @c = TestClassC.new
46
- end
47
-
48
- def test_should_create_LiquidDropClass
49
- assert TestClassA::LiquidDropClass
50
- assert TestClassB::LiquidDropClass
51
- assert TestClassC::LiquidDropClass
52
- end
53
-
54
- def test_should_respond_to_liquid
55
- assert @a.respond_to?(:to_liquid)
56
- assert @b.respond_to?(:to_liquid)
57
- assert @c.respond_to?(:to_liquid)
58
- end
59
-
60
- def test_should_return_LiquidDropClass_object
61
- assert @a.to_liquid.is_a?(TestClassA::LiquidDropClass)
62
- assert @b.to_liquid.is_a?(TestClassB::LiquidDropClass)
63
- assert @c.to_liquid.is_a?(TestClassC::LiquidDropClass)
64
- end
65
-
66
- def test_should_respond_to_liquid_methods
67
- assert @a.to_liquid.respond_to?(:allowedA)
68
- assert @a.to_liquid.respond_to?(:chainedB)
69
- assert @b.to_liquid.respond_to?(:allowedB)
70
- assert @b.to_liquid.respond_to?(:chainedC)
71
- assert @c.to_liquid.respond_to?(:allowedC)
72
- assert @c.to_liquid.respond_to?(:another_allowedC)
73
- end
74
-
75
- def test_should_not_respond_to_restricted_methods
76
- assert ! @a.to_liquid.respond_to?(:restricted)
77
- end
78
-
79
- def test_should_use_regular_objects_as_drops
80
- assert_equal 'allowedA', Liquid::Template.parse("{{ a.allowedA }}").render('a'=>@a)
81
- assert_equal 'allowedB', Liquid::Template.parse("{{ a.chainedB.allowedB }}").render('a'=>@a)
82
- assert_equal 'allowedC', Liquid::Template.parse("{{ a.chainedB.chainedC.allowedC }}").render('a'=>@a)
83
- assert_equal 'another_allowedC', Liquid::Template.parse("{{ a.chainedB.chainedC.another_allowedC }}").render('a'=>@a)
84
- assert_equal '', Liquid::Template.parse("{{ a.restricted }}").render('a'=>@a)
85
- assert_equal '', Liquid::Template.parse("{{ a.unknown }}").render('a'=>@a)
86
- end
87
- end # ModuleExTest
@@ -1,116 +0,0 @@
1
- require 'test_helper'
2
-
3
- module FunnyFilter
4
- def make_funny(input)
5
- 'LOL'
6
- end
7
-
8
- def cite_funny(input)
9
- "LOL: #{input}"
10
- end
11
-
12
- def add_smiley(input, smiley = ":-)")
13
- "#{input} #{smiley}"
14
- end
15
-
16
- def add_tag(input, tag = "p", id = "foo")
17
- %|<#{tag} id="#{id}">#{input}</#{tag}>|
18
- end
19
-
20
- def paragraph(input)
21
- "<p>#{input}</p>"
22
- end
23
-
24
- def link_to(name, url)
25
- %|<a href="#{url}">#{name}</a>|
26
- end
27
-
28
- end
29
-
30
- class OutputTest < Test::Unit::TestCase
31
- include Liquid
32
-
33
- def setup
34
- @assigns = {
35
- 'best_cars' => 'bmw',
36
- 'car' => {'bmw' => 'good', 'gm' => 'bad'}
37
- }
38
- end
39
-
40
- def test_variable
41
- text = %| {{best_cars}} |
42
-
43
- expected = %| bmw |
44
- assert_equal expected, Template.parse(text).render(@assigns)
45
- end
46
-
47
- def test_variable_traversing
48
- text = %| {{car.bmw}} {{car.gm}} {{car.bmw}} |
49
-
50
- expected = %| good bad good |
51
- assert_equal expected, Template.parse(text).render(@assigns)
52
- end
53
-
54
- def test_variable_piping
55
- text = %( {{ car.gm | make_funny }} )
56
- expected = %| LOL |
57
-
58
- assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
59
- end
60
-
61
- def test_variable_piping_with_input
62
- text = %( {{ car.gm | cite_funny }} )
63
- expected = %| LOL: bad |
64
-
65
- assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
66
- end
67
-
68
- def test_variable_piping_with_args
69
- text = %! {{ car.gm | add_smiley : ':-(' }} !
70
- expected = %| bad :-( |
71
-
72
- assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
73
- end
74
-
75
- def test_variable_piping_with_no_args
76
- text = %! {{ car.gm | add_smiley }} !
77
- expected = %| bad :-) |
78
-
79
- assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
80
- end
81
-
82
- def test_multiple_variable_piping_with_args
83
- text = %! {{ car.gm | add_smiley : ':-(' | add_smiley : ':-('}} !
84
- expected = %| bad :-( :-( |
85
-
86
- assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
87
- end
88
-
89
- def test_variable_piping_with_args
90
- text = %! {{ car.gm | add_tag : 'span', 'bar'}} !
91
- expected = %| <span id="bar">bad</span> |
92
-
93
- assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
94
- end
95
-
96
- def test_variable_piping_with_variable_args
97
- text = %! {{ car.gm | add_tag : 'span', car.bmw}} !
98
- expected = %| <span id="good">bad</span> |
99
-
100
- assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
101
- end
102
-
103
- def test_multiple_pipings
104
- text = %( {{ best_cars | cite_funny | paragraph }} )
105
- expected = %| <p>LOL: bmw</p> |
106
-
107
- assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
108
- end
109
-
110
- def test_link_to
111
- text = %( {{ 'Typo' | link_to: 'http://typo.leetsoft.com' }} )
112
- expected = %| <a href="http://typo.leetsoft.com">Typo</a> |
113
-
114
- assert_equal expected, Template.parse(text).render(@assigns, :filters => [FunnyFilter])
115
- end
116
- end # OutputTest
@@ -1,52 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ParsingQuirksTest < Test::Unit::TestCase
4
- include Liquid
5
-
6
- def test_error_with_css
7
- text = %| div { font-weight: bold; } |
8
- template = Template.parse(text)
9
-
10
- assert_equal text, template.render
11
- assert_equal [String], template.root.nodelist.collect {|i| i.class}
12
- end
13
-
14
- def test_raise_on_single_close_bracet
15
- assert_raise(SyntaxError) do
16
- Template.parse("text {{method} oh nos!")
17
- end
18
- end
19
-
20
- def test_raise_on_label_and_no_close_bracets
21
- assert_raise(SyntaxError) do
22
- Template.parse("TEST {{ ")
23
- end
24
- end
25
-
26
- def test_raise_on_label_and_no_close_bracets_percent
27
- assert_raise(SyntaxError) do
28
- Template.parse("TEST {% ")
29
- end
30
- end
31
-
32
- def test_error_on_empty_filter
33
- assert_nothing_raised do
34
- Template.parse("{{test |a|b|}}")
35
- Template.parse("{{test}}")
36
- Template.parse("{{|test|}}")
37
- end
38
- end
39
-
40
- def test_meaningless_parens
41
- assigns = {'b' => 'bar', 'c' => 'baz'}
42
- markup = "a == 'foo' or (b == 'bar' and c == 'baz') or false"
43
- assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}", assigns)
44
- end
45
-
46
- def test_unexpected_characters_silently_eat_logic
47
- markup = "true && false"
48
- assert_template_result(' YES ',"{% if #{markup} %} YES {% endif %}")
49
- markup = "false || true"
50
- assert_template_result('',"{% if #{markup} %} YES {% endif %}")
51
- end
52
- end # ParsingQuirksTest
@@ -1,44 +0,0 @@
1
- require 'test_helper'
2
-
3
- class RegexpTest < Test::Unit::TestCase
4
- include Liquid
5
-
6
- def test_empty
7
- assert_equal [], ''.scan(QuotedFragment)
8
- end
9
-
10
- def test_quote
11
- assert_equal ['"arg 1"'], '"arg 1"'.scan(QuotedFragment)
12
- end
13
-
14
- def test_words
15
- assert_equal ['arg1', 'arg2'], 'arg1 arg2'.scan(QuotedFragment)
16
- end
17
-
18
- def test_tags
19
- assert_equal ['<tr>', '</tr>'], '<tr> </tr>'.scan(QuotedFragment)
20
- assert_equal ['<tr></tr>'], '<tr></tr>'.scan(QuotedFragment)
21
- assert_equal ['<style', 'class="hello">', '</style>'], %|<style class="hello">' </style>|.scan(QuotedFragment)
22
- end
23
-
24
- def test_quoted_words
25
- assert_equal ['arg1', 'arg2', '"arg 3"'], 'arg1 arg2 "arg 3"'.scan(QuotedFragment)
26
- end
27
-
28
- def test_quoted_words
29
- assert_equal ['arg1', 'arg2', "'arg 3'"], 'arg1 arg2 \'arg 3\''.scan(QuotedFragment)
30
- end
31
-
32
- def test_quoted_words_in_the_middle
33
- assert_equal ['arg1', 'arg2', '"arg 3"', 'arg4'], 'arg1 arg2 "arg 3" arg4 '.scan(QuotedFragment)
34
- end
35
-
36
- def test_variable_parser
37
- assert_equal ['var'], 'var'.scan(VariableParser)
38
- assert_equal ['var', 'method'], 'var.method'.scan(VariableParser)
39
- assert_equal ['var', '[method]'], 'var[method]'.scan(VariableParser)
40
- assert_equal ['var', '[method]', '[0]'], 'var[method][0]'.scan(VariableParser)
41
- assert_equal ['var', '["method"]', '[0]'], 'var["method"][0]'.scan(VariableParser)
42
- assert_equal ['var', '[method]', '[0]', 'method'], 'var[method][0].method'.scan(VariableParser)
43
- end
44
- end # RegexpTest
@@ -1,64 +0,0 @@
1
- require 'test_helper'
2
-
3
- module SecurityFilter
4
- def add_one(input)
5
- "#{input} + 1"
6
- end
7
- end
8
-
9
- class SecurityTest < Test::Unit::TestCase
10
- include Liquid
11
-
12
- def test_no_instance_eval
13
- text = %( {{ '1+1' | instance_eval }} )
14
- expected = %| 1+1 |
15
-
16
- assert_equal expected, Template.parse(text).render(@assigns)
17
- end
18
-
19
- def test_no_existing_instance_eval
20
- text = %( {{ '1+1' | __instance_eval__ }} )
21
- expected = %| 1+1 |
22
-
23
- assert_equal expected, Template.parse(text).render(@assigns)
24
- end
25
-
26
-
27
- def test_no_instance_eval_after_mixing_in_new_filter
28
- text = %( {{ '1+1' | instance_eval }} )
29
- expected = %| 1+1 |
30
-
31
- assert_equal expected, Template.parse(text).render(@assigns)
32
- end
33
-
34
-
35
- def test_no_instance_eval_later_in_chain
36
- text = %( {{ '1+1' | add_one | instance_eval }} )
37
- expected = %| 1+1 + 1 |
38
-
39
- assert_equal expected, Template.parse(text).render(@assigns, :filters => SecurityFilter)
40
- end
41
-
42
- def test_does_not_add_filters_to_symbol_table
43
- current_symbols = Symbol.all_symbols
44
-
45
- test = %( {{ "some_string" | a_bad_filter }} )
46
-
47
- template = Template.parse(test)
48
- assert_equal [], (Symbol.all_symbols - current_symbols)
49
-
50
- template.render
51
- assert_equal [], (Symbol.all_symbols - current_symbols)
52
- end
53
-
54
- def test_does_not_add_drop_methods_to_symbol_table
55
- current_symbols = Symbol.all_symbols
56
-
57
- drop = Drop.new
58
- drop.invoke_drop("custom_method_1")
59
- drop.invoke_drop("custom_method_2")
60
- drop.invoke_drop("custom_method_3")
61
-
62
- assert_equal [], (Symbol.all_symbols - current_symbols)
63
- end
64
- end # SecurityTest