Compare commits

..

10 Commits

Author SHA1 Message Date
Mike Angell
b3c6a523b5 Shorten default_proc check 2019-08-31 19:56:28 +10:00
Mike Angell
c34aba4d1a Add blank scope constant 2019-08-31 19:55:04 +10:00
Mike Angell
8933044cb5 static_environment bug 2019-08-30 10:04:18 +10:00
Mike Angell
ba0edc661d Merge branch 'master' into simplify_find_variable 2019-08-30 10:02:29 +10:00
Mike Angell
c06a325b3b Changing to keep default_proc support 2019-08-30 09:55:49 +10:00
Samuel Doiron
34083c96d5 Merge pull request #1122 from Shopify/render-tag
Add new `{% render %}` tag
2019-08-29 16:49:56 -04:00
Justin Li
f3112fc038 Merge pull request #1136 from ashmaroli/travis-selected-branches
Build only pushes to certain branches on Travis CI
2019-08-29 13:47:59 -04:00
Mike Angell
6590815b00 Confirm nil and false values are maintained 2019-08-29 16:16:54 +10:00
Mike Angell
d1deb89085 Remove support for fallback proc on last scope
This was introduced but never actually used. The introduction of environments.last as the fallback for unfound variables means this functionality is already broken
2019-08-29 11:40:08 +10:00
Ashwin Maroli
b3097f143c Build only pushes to certain branches on Travis CI 2019-08-28 21:28:49 +05:30
3 changed files with 21 additions and 28 deletions

View File

@@ -1,4 +1,5 @@
language: ruby
cache: bundler
rvm:
- 2.4
@@ -9,7 +10,6 @@ rvm:
- jruby-head
- truffleruby
matrix:
include:
- rvm: *latest_ruby
@@ -20,9 +20,11 @@ matrix:
- rvm: jruby-head
- rvm: truffleruby
cache: bundler
script: bundle exec rake
branches:
only:
- master
- gh-pages
- /.*-stable/
notifications:
disable: true

View File

@@ -15,6 +15,8 @@ module Liquid
attr_reader :scopes, :errors, :registers, :environments, :resource_limits, :static_registers, :static_environments
attr_accessor :exception_renderer, :template_name, :partial, :global_filter, :strict_variables, :strict_filters
BLANK_SCOPE = {}
# rubocop:disable Metrics/ParameterLists
def self.build(environments: {}, outer_scope: {}, registers: {}, rethrow_errors: false, resource_limits: nil, static_registers: {}, static_environments: {})
new(environments, outer_scope, registers, rethrow_errors, resource_limits, static_registers, static_environments)
@@ -191,15 +193,12 @@ module Liquid
def find_variable(key, raise_on_not_found: true)
# This was changed from find() to find_index() because this is a very hot
# path and find_index() is optimized in MRI to reduce object allocation
index = @scopes.find_index { |s| s.key?(key) }
scope = (index = @scopes.find_index { |s| s.key?(key) }) && @scopes[index]
scope ||= (index = @environments.find_index { |s| s.key?(key) || s.default_proc }) && @environments[index]
scope ||= (index = @static_environments.find_index { |s| s.key?(key) }) && @static_environments[index]
scope ||= BLANK_SCOPE
variable = if index
lookup_and_evaluate(@scopes[index], key, raise_on_not_found: raise_on_not_found)
else
try_variable_find_in_environments(key, raise_on_not_found: raise_on_not_found)
end
variable = variable.to_liquid
variable = lookup_and_evaluate(scope, key, raise_on_not_found: raise_on_not_found).to_liquid
variable.context = self if variable.respond_to?(:context=)
variable
@@ -227,22 +226,6 @@ module Liquid
attr_reader :base_scope_depth
def try_variable_find_in_environments(key, raise_on_not_found:)
@environments.each do |environment|
found_variable = lookup_and_evaluate(environment, key, raise_on_not_found: raise_on_not_found)
if !found_variable.nil? || @strict_variables && raise_on_not_found
return found_variable
end
end
@static_environments.each do |environment|
found_variable = lookup_and_evaluate(environment, key, raise_on_not_found: raise_on_not_found)
if !found_variable.nil? || @strict_variables && raise_on_not_found
return found_variable
end
end
nil
end
def check_overflow
raise StackLevelError, "Nesting too deep".freeze if overflow?
end

View File

@@ -86,6 +86,14 @@ class VariableTest < Minitest::Test
assert_equal "Unknown variable 'test'", e.message
end
def test_environment_falsy
template = Template.parse(%({{ test }}{% assign test = 'bar' %}{{ test }}))
template.assigns['test'] = 'foo'
assert_equal 'foobar', template.render!
assert_equal 'bar', template.render!('test' => nil)
assert_equal 'falsebar', template.render!('test' => false)
end
def test_multiline_variable
assert_equal 'worked', Template.parse("{{\ntest\n}}").render!('test' => 'worked')
end