liquid 2.5.0 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -93,10 +93,8 @@ module Liquid
93
93
  # map/collect on a given property
94
94
  def map(input, property)
95
95
  ary = [input].flatten
96
- if ary.first.respond_to?('[]') and !ary.first[property].nil?
97
- ary.map {|e| e[property] }
98
- elsif ary.first.respond_to?(property)
99
- ary.map {|e| e.send(property) }
96
+ ary.map do |e|
97
+ e.respond_to?('[]') ? e[property] : nil
100
98
  end
101
99
  end
102
100
 
@@ -71,23 +71,29 @@ class DropsTest < Test::Unit::TestCase
71
71
  include Liquid
72
72
 
73
73
  def test_product_drop
74
-
75
74
  assert_nothing_raised do
76
75
  tpl = Liquid::Template.parse( ' ' )
77
76
  tpl.render('product' => ProductDrop.new)
78
77
  end
79
78
  end
80
79
 
80
+ def test_drop_does_only_respond_to_whitelisted_methods
81
+ assert_equal "", Liquid::Template.parse("{{ product.inspect }}").render('product' => ProductDrop.new)
82
+ assert_equal "", Liquid::Template.parse("{{ product.pretty_inspect }}").render('product' => ProductDrop.new)
83
+ assert_equal "", Liquid::Template.parse("{{ product.whatever }}").render('product' => ProductDrop.new)
84
+ assert_equal "", Liquid::Template.parse('{{ product | map: "inspect" }}').render('product' => ProductDrop.new)
85
+ assert_equal "", Liquid::Template.parse('{{ product | map: "pretty_inspect" }}').render('product' => ProductDrop.new)
86
+ assert_equal "", Liquid::Template.parse('{{ product | map: "whatever" }}').render('product' => ProductDrop.new)
87
+ end
88
+
81
89
  def test_text_drop
82
90
  output = Liquid::Template.parse( ' {{ product.texts.text }} ' ).render('product' => ProductDrop.new)
83
91
  assert_equal ' text1 ', output
84
-
85
92
  end
86
93
 
87
94
  def test_unknown_method
88
95
  output = Liquid::Template.parse( ' {{ product.catchall.unknown }} ' ).render('product' => ProductDrop.new)
89
96
  assert_equal ' method: unknown ', output
90
-
91
97
  end
92
98
 
93
99
  def test_integer_argument_drop
@@ -86,6 +86,11 @@ class StandardFiltersTest < Test::Unit::TestCase
86
86
  'ary' => [{'foo' => {'bar' => 'a'}}, {'foo' => {'bar' => 'b'}}, {'foo' => {'bar' => 'c'}}]
87
87
  end
88
88
 
89
+ def test_map_doesnt_call_arbitrary_stuff
90
+ assert_equal "", Liquid::Template.parse('{{ "foo" | map: "__id__" }}').render
91
+ assert_equal "", Liquid::Template.parse('{{ "foo" | map: "inspect" }}').render
92
+ end
93
+
89
94
  def test_date
90
95
  assert_equal 'May', @filters.date(Time.parse("2006-05-05 10:00:00"), "%B")
91
96
  assert_equal 'June', @filters.date(Time.parse("2006-06-05 10:00:00"), "%B")
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquid
3
3
  version: !ruby/object:Gem::Version
4
+ version: 2.5.1
4
5
  prerelease:
5
- version: 2.5.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tobias Luetke
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-06 00:00:00.000000000 Z
12
+ date: 2013-07-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -56,7 +56,6 @@ files:
56
56
  - lib/liquid.rb
57
57
  - MIT-LICENSE
58
58
  - README.md
59
- - History.md
60
59
  - test/liquid/assign_test.rb
61
60
  - test/liquid/block_test.rb
62
61
  - test/liquid/capture_test.rb
@@ -87,6 +86,7 @@ files:
87
86
  - test/liquid/template_test.rb
88
87
  - test/liquid/variable_test.rb
89
88
  - test/test_helper.rb
89
+ - History.md
90
90
  homepage: http://www.liquidmarkup.org
91
91
  licenses: []
92
92
  post_install_message:
@@ -94,17 +94,17 @@ rdoc_options: []
94
94
  require_paths:
95
95
  - lib
96
96
  required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
97
98
  requirements:
98
99
  - - ! '>='
99
100
  - !ruby/object:Gem::Version
100
101
  version: '0'
101
- none: false
102
102
  required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
103
104
  requirements:
104
105
  - - ! '>='
105
106
  - !ruby/object:Gem::Version
106
107
  version: 1.3.7
107
- none: false
108
108
  requirements: []
109
109
  rubyforge_project:
110
110
  rubygems_version: 1.8.23