Use early returns rather than large if in Variable#taint_check

This commit is contained in:
Dylan Thacker-Smith
2015-07-07 15:56:03 -04:00
parent 80b6ac3bc7
commit c4c398174b
+13 -12
View File
@@ -107,20 +107,21 @@ module Liquid
end end
def taint_check(context, obj) def taint_check(context, obj)
if obj.tainted? && Template.taint_mode != :lax return unless obj.tainted?
@markup =~ QuotedFragment return if Template.taint_mode == :lax
name = Regexp.last_match(0)
error = TaintedError.new("variable '#{name}' is tainted and was not escaped") @markup =~ QuotedFragment
error.line_number = line_number name = Regexp.last_match(0)
error.template_name = context.template_name
case Template.taint_mode error = TaintedError.new("variable '#{name}' is tainted and was not escaped")
when :warn error.line_number = line_number
context.warnings << error error.template_name = context.template_name
when :error
raise error case Template.taint_mode
end when :warn
context.warnings << error
when :error
raise error
end end
end end
end end