Compare commits

...

4 Commits

Author SHA1 Message Date
Tom Burns
9559d69e11 blacklist inspect et al from being called on drops 2012-12-18 13:50:02 -05:00
Dylan Smith
50bd34fd78 Merge pull request #161 from Shopify/fix-filter-parser-regex
Fix filter parser regex for filter args without separating spaces.
2012-12-18 10:13:21 -08:00
Dylan Smith
ee41b3f4a3 Fix filter parser regex for filter args without separating spaces.
The regex was using \S+ to match the comma between the filters
arguments, but would continue to match idependent quote characters and
filter separators. This can result in multiple filters being interpreted as
a single one with many arguments.
2012-12-18 01:23:31 -05:00
Tobias Lütke
05d9976e16 fix benchmark 2012-10-29 16:47:57 -04:00
5 changed files with 40 additions and 5 deletions

View File

@@ -20,9 +20,10 @@ module Liquid
# Your drop can either implement the methods sans any parameters or implement the before_method(name) method which is a
# catch all.
class Drop
attr_writer :context
EMPTY_STRING = ''.freeze
METHOD_BLACKLIST = [:dup, :clone, :singleton_class, :eval, :class_eval, :`, :inspect]
attr_writer :context
# Catch all for the method
def before_method(method)
@@ -47,5 +48,9 @@ module Liquid
end
alias :[] :invoke_drop
METHOD_BLACKLIST.each do |blacklisted|
define_method(blacklisted) {nil}
end
end
end

View File

@@ -11,7 +11,7 @@ module Liquid
# {{ user | link }}
#
class Variable
FilterParser = /(?:#{FilterSeparator}|(?:\s*(?!(?:#{FilterSeparator}))(?:#{QuotedFragment}|\S+)\s*)+)/o
FilterParser = /(?:#{FilterSeparator}|(?:\s*(?:#{QuotedFragment}|#{ArgumentSeparator})\s*)+)/o
attr_accessor :filters, :name
def initialize(markup)

View File

@@ -5,6 +5,7 @@ require File.dirname(__FILE__) + '/theme_runner'
profiler = ThemeRunner.new
Benchmark.bmbm do |x|
x.report("parse & run:") { 10.times { profiler.run(false) } }
x.report("parse:") { 100.times { profiler.compile } }
x.report("parse & run:") { 100.times { profiler.run } }
end

View File

@@ -27,8 +27,33 @@ class ThemeRunner
end.compact
end
def compile
# Dup assigns because will make some changes to them
def run()
@tests.each do |liquid, layout, template_name|
tmpl = Liquid::Template.new
tmpl.parse(liquid)
tmpl = Liquid::Template.new
tmpl.parse(layout)
end
end
def run
# Dup assigns because will make some changes to them
assigns = Database.tables.dup
@tests.each do |liquid, layout, template_name|
# Compute page_tempalte outside of profiler run, uninteresting to profiler
page_template = File.basename(template_name, File.extname(template_name))
compile_and_render(liquid, layout, assigns, page_template)
end
end
def run_profile
RubyProf.measure_mode = RubyProf::WALL_TIME
# Dup assigns because will make some changes to them

View File

@@ -66,6 +66,10 @@ class VariableTest < Test::Unit::TestCase
var = Variable.new('hello|textileze|paragraph')
assert_equal 'hello', var.name
assert_equal [[:textileze,[]], [:paragraph,[]]], var.filters
var = Variable.new("hello|replace:'foo','bar'|textileze")
assert_equal 'hello', var.name
assert_equal [[:replace, ["'foo'", "'bar'"]], [:textileze, []]], var.filters
end
def test_symbol