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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 556c422717dbe398a9c414ac93d2d7fa6cf824d9
4
- data.tar.gz: 1b63c67741c2e9c1bb0fa61c0e84856ecd17a6a7
2
+ SHA256:
3
+ metadata.gz: c8408df245a1cc22ee1154fe5387e3e41eb3c740f7277e7d3736c1863d387e47
4
+ data.tar.gz: 64549a58828fd7e9e0eb7310cb4371e75e64a7c3249fe9ebd021039e3334bba1
5
5
  SHA512:
6
- metadata.gz: fefb1fb53e150321193372e6f75dac1b860454a214a16a3cdb526e13d524b00761d50450b986b0ddab7297d253e2db46025e3a23144362b188a974834adfd08d
7
- data.tar.gz: 8e1449c8d9923df9ca9ea64c52848725106d84b39e16311fee5c7a8e006f9b8c78f663efa2574f15d1f32c6bfe7acb1001ac79881fe87435dbd273f5ea7eb213
6
+ metadata.gz: 29aaff16e3bc464712cdcac3aa205df943132198ef9568d46f4a123d327849f7ead7bd669a095eae0425581eb59ea08874ac38664bf9d8df00b0aa99917c7768
7
+ data.tar.gz: 9f6070c39733b7f4064f70676b1f886fc61070f3ba8921360b9c5fcdb09c217b3e58c3d59d8293b24b6c18e55899ed17552a2f867ea8eb95e7dee9a7deb29ae5
data/History.md CHANGED
@@ -1,7 +1,245 @@
1
- # Liquid Version History
1
+ # Liquid Change Log
2
2
 
3
- IMPORTANT: Liquid 2.6 is going to be the last version of Liquid which maintains explicit Ruby 1.8 compatability.
4
- The following releases will only be tested against Ruby 1.9 and Ruby 2.0 and are likely to break on Ruby 1.8.
3
+ ## 5.4.0 2022-07-29
4
+
5
+ ### Breaking Changes
6
+ * Drop support for end-of-life Ruby versions (2.5 and 2.6) (#1578) [Andy Waite]
7
+
8
+ ### Features
9
+ * Allow `#` to be used as an inline comment tag (#1498) [CP Clermont]
10
+
11
+ ### Fixes
12
+ * `PartialCache` now shares snippet cache with subcontexts by default (#1553) [Chris AtLee]
13
+ * Hash registers no longer leak into subcontexts as static registers (#1564) [Chris AtLee]
14
+ * Fix `ParseTreeVisitor` for `with` variable expressions in `Render` tag (#1596) [CP Clermont]
15
+
16
+ ### Changed
17
+ * Liquid::Context#registers now always returns a Liquid::Registers object, though supports the most used Hash functions for compatibility (#1553)
18
+
19
+ ## 5.3.0 2022-03-22
20
+
21
+ ### Fixes
22
+ * StandardFilter: Fix missing @context on iterations (#1525) [Thierry Joyal]
23
+ * Fix warning about block and default value in `static_registers.rb` (#1531) [Peter Zhu]
24
+
25
+ ### Deprecation
26
+ * Condition#evaluate to require mandatory context argument in Liquid 6.0.0 (#1527) [Thierry Joyal]
27
+
28
+ ## 5.2.0 2022-03-01
29
+
30
+ ### Features
31
+ * Add `remove_last`, and `replace_last` filters (#1422) [Anders Hagbard]
32
+ * Eagerly cache global filters (#1524) [Jean Boussier]
33
+
34
+ ### Fixes
35
+ * Fix some internal errors in filters from invalid input (#1476) [Dylan Thacker-Smith]
36
+ * Allow dash in filter kwarg name for consistency with Liquid::C (#1518) [CP Clermont]
37
+
38
+ ## 5.1.0 / 2021-09-09
39
+
40
+ ### Features
41
+ * Add `base64_encode`, `base64_decode`, `base64_url_safe_encode`, and `base64_url_safe_decode` filters (#1450) [Daniel Insley]
42
+ * Introduce `to_liquid_value` in `Liquid::Drop` (#1441) [Michael Go]
43
+
44
+ ### Fixes
45
+ * Fix support for using a String subclass for the liquid source (#1421) [Dylan Thacker-Smith]
46
+ * Add `ParseTreeVisitor` to `RangeLookup` (#1470) [CP Clermont]
47
+ * Translate `RangeError` to `Liquid::Error` for `truncatewords` with large int (#1431) [Dylan Thacker-Smith]
48
+
49
+ ## 5.0.1 / 2021-03-24
50
+
51
+ ### Fixes
52
+ * Add ParseTreeVisitor to Echo tag (#1414) [CP Clermont]
53
+ * Test with ruby 3.0 as the latest ruby version (#1398) [Dylan Thacker-Smith]
54
+ * Handle carriage return in newlines_to_br (#1391) [Unending]
55
+
56
+ ### Performance Improvements
57
+ * Use split limit in truncatewords (#1361) [Dylan Thacker-Smith]
58
+
59
+ ## 5.0.0 / 2021-01-06
60
+
61
+ ### Features
62
+ * Add new `{% render %}` tag (#1122) [Samuel Doiron]
63
+ * Add support for `as` in `{% render %}` and `{% include %}` (#1181) [Mike Angell]
64
+ * Add `{% liquid %}` and `{% echo %}` tags (#1086) [Justin Li]
65
+ * Add [usage tracking](README.md#usage-tracking) [Mike Angell]
66
+ * Add `Tag.disable_tags` for disabling tags that prepend `Tag::Disableable` at render time (#1162, #1274, #1275) [Mike Angell]
67
+ * Support using a profiler for multiple renders (#1365, #1366) [Dylan Thacker-Smith]
68
+
69
+ ### Fixes
70
+ * Fix catastrophic backtracking in `RANGES_REGEX` regular expression (#1357) [Dylan Thacker-Smith]
71
+ * Make sure the for tag's limit and offset are integers (#1094) [David Cornu]
72
+ * Invokable methods for enumerable reject include (#1151) [Thierry Joyal]
73
+ * Allow `default` filter to handle `false` as value (#1144) [Mike Angell]
74
+ * Fix render length resource limit so it doesn't multiply nested output (#1285) [Dylan Thacker-Smith]
75
+ * Fix duplication of text in raw tags (#1304) [Peter Zhu]
76
+ * Fix strict parsing of find variable with a name expression (#1317) [Dylan Thacker-Smith]
77
+ * Use monotonic time to measure durations in Liquid::Profiler (#1362) [Dylan Thacker-Smith]
78
+
79
+ ### Breaking Changes
80
+ * Require Ruby >= 2.5 (#1131, #1310) [Mike Angell, Dylan Thacker-Smith]
81
+ * Remove support for taint checking (#1268) [Dylan Thacker-Smith]
82
+ * Split Strainer class into StrainerFactory and StrainerTemplate (#1208) [Thierry Joyal]
83
+ * Remove handling of a nil context in the Strainer class (#1218) [Thierry Joyal]
84
+ * Handle `BlockBody#blank?` at parse time (#1287) [Dylan Thacker-Smith]
85
+ * Pass the tag markup and tokenizer to `Document#unknown_tag` (#1290) [Dylan Thacker-Smith]
86
+ * And several internal changes
87
+
88
+ ### Performance Improvements
89
+ * Reduce allocations (#1073, #1091, #1115, #1099, #1117, #1141, #1322, #1341) [Richard Monette, Florian Weingarten, Ashwin Maroli]
90
+ * Improve resources limits performance (#1093, #1323) [Florian Weingarten, Dylan Thacker-Smith]
91
+
92
+ ## 4.0.3 / 2019-03-12
93
+
94
+ ### Fixed
95
+ * Fix break and continue tags inside included templates in loops (#1072) [Justin Li]
96
+
97
+ ## 4.0.2 / 2019-03-08
98
+
99
+ ### Changed
100
+ * Add `where` filter (#1026) [Samuel Doiron]
101
+ * Add `ParseTreeVisitor` to iterate the Liquid AST (#1025) [Stephen Paul Weber]
102
+ * Improve `strip_html` performance (#1032) [printercu]
103
+
104
+ ### Fixed
105
+ * Add error checking for invalid combinations of inputs to sort, sort_natural, where, uniq, map, compact filters (#1059) [Garland Zhang]
106
+ * Validate the character encoding in url_decode (#1070) [Clayton Smith]
107
+
108
+ ## 4.0.1 / 2018-10-09
109
+
110
+ ### Changed
111
+ * Add benchmark group in Gemfile (#855) [Jerry Liu]
112
+ * Allow benchmarks to benchmark render by itself (#851) [Jerry Liu]
113
+ * Avoid calling `line_number` on String node when rescuing a render error. (#860) [Dylan Thacker-Smith]
114
+ * Avoid duck typing to detect whether to call render on a node. [Dylan Thacker-Smith]
115
+ * Clarify spelling of `reversed` on `for` block tag (#843) [Mark Crossfield]
116
+ * Replace recursion with loop to avoid potential stack overflow from malicious input (#891, #892) [Dylan Thacker-Smith]
117
+ * Limit block tag nesting to 100 (#894) [Dylan Thacker-Smith]
118
+ * Replace `assert_equal nil` with `assert_nil` (#895) [Dylan Thacker-Smith]
119
+ * Remove Spy Gem (#896) [Dylan Thacker-Smith]
120
+ * Add `collection_name` and `variable_name` reader to `For` block (#909)
121
+ * Symbols render as strings (#920) [Justin Li]
122
+ * Remove default value from Hash objects (#932) [Maxime Bedard]
123
+ * Remove one level of nesting (#944) [Dylan Thacker-Smith]
124
+ * Update Rubocop version (#952) [Justin Li]
125
+ * Add `at_least` and `at_most` filters (#954, #958) [Nithin Bekal]
126
+ * Add a regression test for a liquid-c trim mode bug (#972) [Dylan Thacker-Smith]
127
+ * Use https rather than git protocol to fetch liquid-c [Dylan Thacker-Smith]
128
+ * Add tests against Ruby 2.4 (#963) and 2.5 (#981)
129
+ * Replace RegExp literals with constants (#988) [Ashwin Maroli]
130
+ * Replace unnecessary `#each_with_index` with `#each` (#992) [Ashwin Maroli]
131
+ * Improve the unexpected end delimiter message for block tags. (#1003) [Dylan Thacker-Smith]
132
+ * Refactor and optimize rendering (#1005) [Christopher Aue]
133
+ * Add installation instruction (#1006) [Ben Gift]
134
+ * Remove Circle CI (#1010)
135
+ * Rename deprecated `BigDecimal.new` to `BigDecimal` (#1024) [Koichi ITO]
136
+ * Rename deprecated Rubocop name (#1027) [Justin Li]
137
+
138
+ ### Fixed
139
+ * Handle `join` filter on non String joiners (#857) [Richard Monette]
140
+ * Fix duplicate inclusion condition logic error of `Liquid::Strainer.add_filter` method (#861)
141
+ * Fix `escape`, `url_encode`, `url_decode` not handling non-string values (#898) [Thierry Joyal]
142
+ * Fix raise when variable is defined but nil when using `strict_variables` [Pascal Betz]
143
+ * Fix `sort` and `sort_natural` to handle arrays with nils (#930) [Eric Chan]
144
+
145
+ ## 4.0.0 / 2016-12-14 / branch "4-0-stable"
146
+
147
+ ### Changed
148
+ * Render an opaque internal error by default for non-Liquid::Error (#835) [Dylan Thacker-Smith]
149
+ * Ruby 2.0 support dropped (#832) [Dylan Thacker-Smith]
150
+ * Add to_number Drop method to allow custom drops to work with number filters (#731)
151
+ * Add strict_variables and strict_filters options to detect undefined references (#691)
152
+ * Improve loop performance (#681) [Florian Weingarten]
153
+ * Rename Drop method `before_method` to `liquid_method_missing` (#661) [Thierry Joyal]
154
+ * Add url_decode filter to invert url_encode (#645) [Larry Archer]
155
+ * Add global_filter to apply a filter to all output (#610) [Loren Hale]
156
+ * Add compact filter (#600) [Carson Reinke]
157
+ * Rename deprecated "has_key?" and "has_interrupt?" methods (#593) [Florian Weingarten]
158
+ * Include template name with line numbers in render errors (574) [Dylan Thacker-Smith]
159
+ * Add sort_natural filter (#554) [Martin Hanzel]
160
+ * Add forloop.parentloop as a reference to the parent loop (#520) [Justin Li]
161
+ * Block parsing moved to BlockBody class (#458) [Dylan Thacker-Smith]
162
+ * Add concat filter to concatenate arrays (#429) [Diogo Beato]
163
+ * Ruby 1.9 support dropped (#491) [Justin Li]
164
+ * Liquid::Template.file_system's read_template_file method is no longer passed the context. (#441) [James Reid-Smith]
165
+ * Remove `liquid_methods` (See https://github.com/Shopify/liquid/pull/568 for replacement)
166
+ * Liquid::Template.register_filter raises when the module overrides registered public methods as private or protected (#705) [Gaurav Chande]
167
+
168
+ ### Fixed
169
+
170
+ * Fix variable names being detected as an operator when starting with contains (#788) [Michael Angell]
171
+ * Fix include tag used with strict_variables (#828) [QuickPay]
172
+ * Fix map filter when value is a Proc (#672) [Guillaume Malette]
173
+ * Fix truncate filter when value is not a string (#672) [Guillaume Malette]
174
+ * Fix behaviour of escape filter when input is nil (#665) [Tanel Jakobsoo]
175
+ * Fix sort filter behaviour with empty array input (#652) [Marcel Cary]
176
+ * Fix test failure under certain timezones (#631) [Dylan Thacker-Smith]
177
+ * Fix bug in uniq filter (#595) [Florian Weingarten]
178
+ * Fix bug when "blank" and "empty" are used as variable names (#592) [Florian Weingarten]
179
+ * Fix condition parse order in strict mode (#569) [Justin Li]
180
+ * Fix naming of the "context variable" when dynamically including a template (#559) [Justin Li]
181
+ * Gracefully accept empty strings in the date filter (#555) [Loren Hale]
182
+ * Fix capturing into variables with a hyphen in the name (#505) [Florian Weingarten]
183
+ * Fix case sensitivity regression in date standard filter (#499) [Kelley Reynolds]
184
+ * Disallow filters with no variable in strict mode (#475) [Justin Li]
185
+ * Disallow variable names in the strict parser that are not valid in the lax parser (#463) [Justin Li]
186
+ * Fix BlockBody#warnings taking exponential time to compute (#486) [Justin Li]
187
+
188
+ ## 3.0.5 / 2015-07-23 / branch "3-0-stable"
189
+
190
+ * Fix test failure under certain timezones [Dylan Thacker-Smith]
191
+
192
+ ## 3.0.4 / 2015-07-17
193
+
194
+ * Fix chained access to multi-dimensional hashes [Florian Weingarten]
195
+
196
+ ## 3.0.3 / 2015-05-28
197
+
198
+ * Fix condition parse order in strict mode (#569) [Justin Li]
199
+
200
+ ## 3.0.2 / 2015-04-24
201
+
202
+ * Expose VariableLookup private members (#551) [Justin Li]
203
+ * Documentation fixes
204
+
205
+ ## 3.0.1 / 2015-01-23
206
+
207
+ * Remove duplicate `index0` key in TableRow tag (#502) [Alfred Xing]
208
+
209
+ ## 3.0.0 / 2014-11-12
210
+
211
+ * Removed Block#end_tag. Instead, override parse with `super` followed by your code. See #446 [Dylan Thacker-Smith]
212
+ * Fixed condition with wrong data types (#423) [Bogdan Gusiev]
213
+ * Add url_encode to standard filters (#421) [Derrick Reimer]
214
+ * Add uniq to standard filters [Florian Weingarten]
215
+ * Add exception_handler feature (#397) and #254 [Bogdan Gusiev, Florian Weingarten]
216
+ * Optimize variable parsing to avoid repeated regex evaluation during template rendering #383 [Jason Hiltz-Laforge]
217
+ * Optimize checking for block interrupts to reduce object allocation #380 [Jason Hiltz-Laforge]
218
+ * Properly set context rethrow_errors on render! #349 [Thierry Joyal]
219
+ * Fix broken rendering of variables which are equal to false (#345) [Florian Weingarten]
220
+ * Remove ActionView template handler [Dylan Thacker-Smith]
221
+ * Freeze lots of string literals for new Ruby 2.1 optimization (#297) [Florian Weingarten]
222
+ * Allow newlines in tags and variables (#324) [Dylan Thacker-Smith]
223
+ * Tag#parse is called after initialize, which now takes options instead of tokens as the 3rd argument. See #321 [Dylan Thacker-Smith]
224
+ * Raise `Liquid::ArgumentError` instead of `::ArgumentError` when filter has wrong number of arguments #309 [Bogdan Gusiev]
225
+ * Add a to_s default for liquid drops (#306) [Adam Doeler]
226
+ * Add strip, lstrip, and rstrip to standard filters [Florian Weingarten]
227
+ * Make if, for & case tags return complete and consistent nodelists (#250) [Nick Jones]
228
+ * Prevent arbitrary method invocation on condition objects (#274) [Dylan Thacker-Smith]
229
+ * Don't call to_sym when creating conditions for security reasons (#273) [Bouke van der Bijl]
230
+ * Fix resource counting bug with respond_to?(:length) (#263) [Florian Weingarten]
231
+ * Allow specifying custom patterns for template filenames (#284) [Andrei Gladkyi]
232
+ * Allow drops to optimize loading a slice of elements (#282) [Tom Burns]
233
+ * Support for passing variables to snippets in subdirs (#271) [Joost Hietbrink]
234
+ * Add a class cache to avoid runtime extend calls (#249) [James Tucker]
235
+ * Remove some legacy Ruby 1.8 compatibility code (#276) [Florian Weingarten]
236
+ * Add default filter to standard filters (#267) [Derrick Reimer]
237
+ * Add optional strict parsing and warn parsing (#235) [Tristan Hume]
238
+ * Add I18n syntax error translation (#241) [Simon Hørup Eskildsen, Sirupsen]
239
+ * Make sort filter work on enumerable drops (#239) [Florian Weingarten]
240
+ * Fix clashing method names in enumerable drops (#238) [Florian Weingarten]
241
+ * Make map filter work on enumerable drops (#233) [Florian Weingarten]
242
+ * Improved whitespace stripping for blank blocks, related to #216 [Florian Weingarten]
5
243
 
6
244
  ## 2.6.3 / 2015-07-23 / branch "2-6-stable"
7
245
 
@@ -14,38 +252,46 @@ The following releases will only be tested against Ruby 1.9 and Ruby 2.0 and are
14
252
  ## 2.6.1 / 2014-01-10
15
253
 
16
254
  Security fix, cherry-picked from master (4e14a65):
17
- * Don't call to_sym when creating conditions for security reasons, see #273 [Bouke van der Bijl, bouk]
18
- * Prevent arbitrary method invocation on condition objects, see #274 [Dylan Thacker-Smith, dylanahsmith]
255
+ * Don't call to_sym when creating conditions for security reasons (#273) [Bouke van der Bijl]
256
+ * Prevent arbitrary method invocation on condition objects (#274) [Dylan Thacker-Smith]
19
257
 
20
258
  ## 2.6.0 / 2013-11-25
21
259
 
22
- * ...
260
+ IMPORTANT: Liquid 2.6 is going to be the last version of Liquid which maintains explicit Ruby 1.8 compatability.
261
+ The following releases will only be tested against Ruby 1.9 and Ruby 2.0 and are likely to break on Ruby 1.8.
262
+
23
263
  * Bugfix for #106: fix example servlet [gnowoel]
24
- * Bugfix for #97: strip_html filter supports multi-line tags [Jo Liss, joliss]
25
- * Bugfix for #114: strip_html filter supports style tags [James Allardice, jamesallardice]
26
- * Bugfix for #117: 'now' support for date filter in Ruby 1.9 [Notre Dame Webgroup, ndwebgroup]
27
- * Bugfix for #166: truncate filter on UTF-8 strings with Ruby 1.8 [Florian Weingarten, fw42]
28
- * Bugfix for #204: 'raw' parsing bug [Florian Weingarten, fw42]
29
- * Bugfix for #150: 'for' parsing bug [Peter Schröder, phoet]
30
- * Bugfix for #126: Strip CRLF in strip_newline [Peter Schröder, phoet]
31
- * Bugfix for #174, "can't convert Fixnum into String" for "replace" [wǒ_is神仙, jsw0528]
32
- * Allow a Liquid::Drop to be passed into Template#render [Daniel Huckstep, darkhelmet]
33
- * Resource limits [Florian Weingarten, fw42]
34
- * Add reverse filter [Jay Strybis, unreal]
264
+ * Bugfix for #97: strip_html filter supports multi-line tags [Jo Liss]
265
+ * Bugfix for #114: strip_html filter supports style tags [James Allardice]
266
+ * Bugfix for #117: 'now' support for date filter in Ruby 1.9 [Notre Dame Webgroup]
267
+ * Bugfix for #166: truncate filter on UTF-8 strings with Ruby 1.8 [Florian Weingarten]
268
+ * Bugfix for #204: 'raw' parsing bug [Florian Weingarten]
269
+ * Bugfix for #150: 'for' parsing bug [Peter Schröder]
270
+ * Bugfix for #126: Strip CRLF in strip_newline [Peter Schröder]
271
+ * Bugfix for #174, "can't convert Fixnum into String" for "replace" [jsw0528]
272
+ * Allow a Liquid::Drop to be passed into Template#render [Daniel Huckstep]
273
+ * Resource limits [Florian Weingarten]
274
+ * Add reverse filter [Jay Strybis]
35
275
  * Add utf-8 support
36
- * Use array instead of Hash to keep the registered filters [Tasos Stathopoulos, astathopoulos]
37
- * Cache tokenized partial templates [Tom Burns, boourns]
38
- * Avoid warnings in Ruby 1.9.3 [Marcus Stollsteimer, stomar]
39
- * Better documentation for 'include' tag (closes #163) [Peter Schröder, phoet]
40
- * Use of BigDecimal on filters to have better precision (closes #155) [Arthur Nogueira Neves, arthurnn]
276
+ * Use array instead of Hash to keep the registered filters [Tasos Stathopoulos]
277
+ * Cache tokenized partial templates [Tom Burns]
278
+ * Avoid warnings in Ruby 1.9.3 [Marcus Stollsteimer]
279
+ * Better documentation for 'include' tag (closes #163) [Peter Schröder]
280
+ * Use of BigDecimal on filters to have better precision (closes #155) [Arthur Nogueira Neves]
281
+
282
+ ## 2.5.5 / 2014-01-10 / branch "2-5-stable"
283
+
284
+ Security fix, cherry-picked from master (4e14a65):
285
+ * Don't call to_sym when creating conditions for security reasons (#273) [Bouke van der Bijl]
286
+ * Prevent arbitrary method invocation on condition objects (#274) [Dylan Thacker-Smith]
41
287
 
42
- ## 2.5.4 / 2013-11-11 / branch "2.5-stable"
288
+ ## 2.5.4 / 2013-11-11
43
289
 
44
- * Fix "can't convert Fixnum into String" for "replace", see #173, [wǒ_is神仙, jsw0528]
290
+ * Fix "can't convert Fixnum into String" for "replace" (#173), [jsw0528]
45
291
 
46
292
  ## 2.5.3 / 2013-10-09
47
293
 
48
- * #232, #234, #237: Fix map filter bugs [Florian Weingarten, fw42]
294
+ * #232, #234, #237: Fix map filter bugs [Florian Weingarten]
49
295
 
50
296
  ## 2.5.2 / 2013-09-03 / deleted
51
297
 
@@ -53,7 +299,7 @@ Yanked from rubygems, as it contained too many changes that broke compatibility.
53
299
 
54
300
  ## 2.5.1 / 2013-07-24
55
301
 
56
- * #230: Fix security issue with map filter, Use invoke_drop in map filter [Florian Weingarten, fw42]
302
+ * #230: Fix security issue with map filter, Use invoke_drop in map filter [Florian Weingarten]
57
303
 
58
304
  ## 2.5.0 / 2013-03-06
59
305
 
data/README.md CHANGED
@@ -1,9 +1,12 @@
1
+ [![Build Status](https://api.travis-ci.org/Shopify/liquid.svg?branch=master)](http://travis-ci.org/Shopify/liquid)
2
+ [![Inline docs](http://inch-ci.org/github/Shopify/liquid.svg?branch=master)](http://inch-ci.org/github/Shopify/liquid)
3
+
1
4
  # Liquid template engine
2
5
 
3
6
  * [Contributing guidelines](CONTRIBUTING.md)
4
7
  * [Version history](History.md)
5
- * [Liquid documentation from Shopify](http://docs.shopify.com/themes/liquid-basics)
6
- * [Liquid Wiki from Shopify](http://wiki.shopify.com/Liquid)
8
+ * [Liquid documentation from Shopify](https://shopify.dev/api/liquid)
9
+ * [Liquid Wiki at GitHub](https://github.com/Shopify/liquid/wiki)
7
10
  * [Website](http://liquidmarkup.org/)
8
11
 
9
12
  ## Introduction
@@ -39,6 +42,8 @@ Liquid is a template engine which was written with very specific requirements:
39
42
 
40
43
  ## How to use Liquid
41
44
 
45
+ Install Liquid by adding `gem 'liquid'` to your gemfile.
46
+
42
47
  Liquid supports a very simple API based around the Liquid::Template class.
43
48
  For standard use you can just pass it the content of a file and call render with a parameters hash.
44
49
 
@@ -47,4 +52,63 @@ For standard use you can just pass it the content of a file and call render with
47
52
  @template.render('name' => 'tobi') # => "hi tobi"
48
53
  ```
49
54
 
50
- [![Build Status](https://secure.travis-ci.org/Shopify/liquid.png)](http://travis-ci.org/Shopify/liquid)
55
+ ### Error Modes
56
+
57
+ Setting the error mode of Liquid lets you specify how strictly you want your templates to be interpreted.
58
+ Normally the parser is very lax and will accept almost anything without error. Unfortunately this can make
59
+ it very hard to debug and can lead to unexpected behaviour.
60
+
61
+ Liquid also comes with a stricter parser that can be used when editing templates to give better error messages
62
+ when templates are invalid. You can enable this new parser like this:
63
+
64
+ ```ruby
65
+ Liquid::Template.error_mode = :strict # Raises a SyntaxError when invalid syntax is used
66
+ Liquid::Template.error_mode = :warn # Adds strict errors to template.errors but continues as normal
67
+ Liquid::Template.error_mode = :lax # The default mode, accepts almost anything.
68
+ ```
69
+
70
+ If you want to set the error mode only on specific templates you can pass `:error_mode` as an option to `parse`:
71
+ ```ruby
72
+ Liquid::Template.parse(source, error_mode: :strict)
73
+ ```
74
+ This is useful for doing things like enabling strict mode only in the theme editor.
75
+
76
+ It is recommended that you enable `:strict` or `:warn` mode on new apps to stop invalid templates from being created.
77
+ It is also recommended that you use it in the template editors of existing apps to give editors better error messages.
78
+
79
+ ### Undefined variables and filters
80
+
81
+ By default, the renderer doesn't raise or in any other way notify you if some variables or filters are missing, i.e. not passed to the `render` method.
82
+ You can improve this situation by passing `strict_variables: true` and/or `strict_filters: true` options to the `render` method.
83
+ When one of these options is set to true, all errors about undefined variables and undefined filters will be stored in `errors` array of a `Liquid::Template` instance.
84
+ Here are some examples:
85
+
86
+ ```ruby
87
+ template = Liquid::Template.parse("{{x}} {{y}} {{z.a}} {{z.b}}")
88
+ template.render({ 'x' => 1, 'z' => { 'a' => 2 } }, { strict_variables: true })
89
+ #=> '1 2 ' # when a variable is undefined, it's rendered as nil
90
+ template.errors
91
+ #=> [#<Liquid::UndefinedVariable: Liquid error: undefined variable y>, #<Liquid::UndefinedVariable: Liquid error: undefined variable b>]
92
+ ```
93
+
94
+ ```ruby
95
+ template = Liquid::Template.parse("{{x | filter1 | upcase}}")
96
+ template.render({ 'x' => 'foo' }, { strict_filters: true })
97
+ #=> '' # when at least one filter in the filter chain is undefined, a whole expression is rendered as nil
98
+ template.errors
99
+ #=> [#<Liquid::UndefinedFilter: Liquid error: undefined filter filter1>]
100
+ ```
101
+
102
+ If you want to raise on a first exception instead of pushing all of them in `errors`, you can use `render!` method:
103
+
104
+ ```ruby
105
+ template = Liquid::Template.parse("{{x}} {{y}}")
106
+ template.render!({ 'x' => 1}, { strict_variables: true })
107
+ #=> Liquid::UndefinedVariable: Liquid error: undefined variable y
108
+ ```
109
+
110
+ ### Usage tracking
111
+
112
+ To help track usages of a feature or code path in production, we have released opt-in usage tracking. To enable this, we provide an empty `Liquid:: Usage.increment` method which you can customize to your needs. The feature is well suited to https://github.com/Shopify/statsd-instrument. However, the choice of implementation is up to you.
113
+
114
+ Once you have enabled usage tracking, we recommend reporting any events through Github Issues that your system may be logging. It is highly likely this event has been added to consider deprecating or improving code specific to this event, so please raise any concerns.
data/lib/liquid/block.rb CHANGED
@@ -1,126 +1,94 @@
1
- module Liquid
1
+ # frozen_string_literal: true
2
2
 
3
+ module Liquid
3
4
  class Block < Tag
4
- IsTag = /^#{TagStart}/o
5
- IsVariable = /^#{VariableStart}/o
6
- FullToken = /^#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}$/o
7
- ContentOfVariable = /^#{VariableStart}(.*)#{VariableEnd}$/o
5
+ MAX_DEPTH = 100
6
+
7
+ def initialize(tag_name, markup, options)
8
+ super
9
+ @blank = true
10
+ end
8
11
 
9
12
  def parse(tokens)
10
- @nodelist ||= []
11
- @nodelist.clear
12
-
13
- while token = tokens.shift
14
-
15
- case token
16
- when IsTag
17
- if token =~ FullToken
18
-
19
- # if we found the proper block delimiter just end parsing here and let the outer block
20
- # proceed
21
- if block_delimiter == $1
22
- end_tag
23
- return
24
- end
25
-
26
- # fetch the tag from registered blocks
27
- if tag = Template.tags[$1]
28
- @nodelist << tag.new($1, $2, tokens)
29
- else
30
- # this tag is not registered with the system
31
- # pass it to the current block for special handling or error reporting
32
- unknown_tag($1, $2, tokens)
33
- end
34
- else
35
- raise SyntaxError, "Tag '#{token}' was not properly terminated with regexp: #{TagEnd.inspect} "
36
- end
37
- when IsVariable
38
- @nodelist << create_variable(token)
39
- when ''
40
- # pass
41
- else
42
- @nodelist << token
43
- end
13
+ @body = new_body
14
+ while parse_body(@body, tokens)
44
15
  end
16
+ @body.freeze
17
+ end
18
+
19
+ # For backwards compatibility
20
+ def render(context)
21
+ @body.render(context)
22
+ end
45
23
 
46
- # Make sure that it's ok to end parsing in the current block.
47
- # Effectively this method will throw an exception unless the current block is
48
- # of type Document
49
- assert_missing_delimitation!
24
+ def blank?
25
+ @blank
50
26
  end
51
27
 
52
- def end_tag
28
+ def nodelist
29
+ @body.nodelist
53
30
  end
54
31
 
55
- def unknown_tag(tag, params, tokens)
56
- case tag
57
- when 'else'
58
- raise SyntaxError, "#{block_name} tag does not expect else tag"
59
- when 'end'
60
- raise SyntaxError, "'end' is not a valid delimiter for #{block_name} tags. use #{block_delimiter}"
32
+ def unknown_tag(tag_name, _markup, _tokenizer)
33
+ Block.raise_unknown_tag(tag_name, block_name, block_delimiter, parse_context)
34
+ end
35
+
36
+ # @api private
37
+ def self.raise_unknown_tag(tag, block_name, block_delimiter, parse_context)
38
+ if tag == 'else'
39
+ raise SyntaxError, parse_context.locale.t("errors.syntax.unexpected_else",
40
+ block_name: block_name)
41
+ elsif tag.start_with?('end')
42
+ raise SyntaxError, parse_context.locale.t("errors.syntax.invalid_delimiter",
43
+ tag: tag,
44
+ block_name: block_name,
45
+ block_delimiter: block_delimiter)
61
46
  else
62
- raise SyntaxError, "Unknown tag '#{tag}'"
47
+ raise SyntaxError, parse_context.locale.t("errors.syntax.unknown_tag", tag: tag)
63
48
  end
64
49
  end
65
50
 
66
- def block_delimiter
67
- "end#{block_name}"
51
+ def raise_tag_never_closed(block_name)
52
+ raise SyntaxError, parse_context.locale.t("errors.syntax.tag_never_closed", block_name: block_name)
68
53
  end
69
54
 
70
55
  def block_name
71
56
  @tag_name
72
57
  end
73
58
 
74
- def create_variable(token)
75
- token.scan(ContentOfVariable) do |content|
76
- return Variable.new(content.first)
77
- end
78
- raise SyntaxError.new("Variable '#{token}' was not properly terminated with regexp: #{VariableEnd.inspect} ")
59
+ def block_delimiter
60
+ @block_delimiter ||= "end#{block_name}"
79
61
  end
80
62
 
81
- def render(context)
82
- render_all(@nodelist, context)
63
+ private
64
+
65
+ # @api public
66
+ def new_body
67
+ parse_context.new_block_body
83
68
  end
84
69
 
85
- protected
70
+ # @api public
71
+ def parse_body(body, tokens)
72
+ if parse_context.depth >= MAX_DEPTH
73
+ raise StackLevelError, "Nesting too deep"
74
+ end
75
+ parse_context.depth += 1
76
+ begin
77
+ body.parse(tokens, parse_context) do |end_tag_name, end_tag_params|
78
+ @blank &&= body.blank?
86
79
 
87
- def assert_missing_delimitation!
88
- raise SyntaxError.new("#{block_name} tag was never closed")
89
- end
80
+ return false if end_tag_name == block_delimiter
81
+ raise_tag_never_closed(block_name) unless end_tag_name
90
82
 
91
- def render_all(list, context)
92
- output = []
93
- context.resource_limits[:render_length_current] = 0
94
- context.resource_limits[:render_score_current] += list.length
95
-
96
- list.each do |token|
97
- # Break out if we have any unhanded interrupts.
98
- break if context.has_interrupt?
99
-
100
- begin
101
- # If we get an Interrupt that means the block must stop processing. An
102
- # Interrupt is any command that stops block execution such as {% break %}
103
- # or {% continue %}
104
- if token.is_a? Continue or token.is_a? Break
105
- context.push_interrupt(token.interrupt)
106
- break
107
- end
108
-
109
- token_output = (token.respond_to?(:render) ? token.render(context) : token)
110
- context.resource_limits[:render_length_current] += (token_output.respond_to?(:length) ? token_output.length : 1)
111
- if context.resource_limits_reached?
112
- context.resource_limits[:reached] = true
113
- raise MemoryError.new("Memory limits exceeded")
114
- end
115
- output << token_output
116
- rescue MemoryError => e
117
- raise e
118
- rescue ::StandardError => e
119
- output << (context.handle_error(e))
83
+ # this tag is not registered with the system
84
+ # pass it to the current block for special handling or error reporting
85
+ unknown_tag(end_tag_name, end_tag_params, tokens)
120
86
  end
87
+ ensure
88
+ parse_context.depth -= 1
121
89
  end
122
90
 
123
- output.join
91
+ true
124
92
  end
125
93
  end
126
94
  end