Class: Liquid::Expression
- Inherits:
-
Object
- Object
- Liquid::Expression
- Defined in:
- lib/liquid/expression.rb
Constant Summary collapse
- LITERALS =
{ nil => nil, 'nil' => nil, 'null' => nil, '' => nil, 'true' => true, 'false' => false, 'blank' => '', 'empty' => '' }.freeze
- INTEGERS_REGEX =
/\A(-?\d+)\z/
- FLOATS_REGEX =
/\A(-?\d[\d\.]+)\z/
- RANGES_REGEX =
Use an atomic group (?>…) to avoid pathological backtracing from malicious input as described in github.com/Shopify/liquid/issues/1357
/\A\(\s*(?>(\S+)\s*\.\.)\s*(\S+)\s*\)\z/
Class Method Summary collapse
Class Method Details
.parse(markup) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/liquid/expression.rb', line 23 def self.parse(markup) return nil unless markup markup = markup.strip if (markup.start_with?('"') && markup.end_with?('"')) || (markup.start_with?("'") && markup.end_with?("'")) return markup[1..-2] end case markup when INTEGERS_REGEX Regexp.last_match(1).to_i when RANGES_REGEX RangeLookup.parse(Regexp.last_match(1), Regexp.last_match(2)) when FLOATS_REGEX Regexp.last_match(1).to_f else if LITERALS.key?(markup) LITERALS[markup] else VariableLookup.parse(markup) end end end |