Class: Brakeman::Haml6TemplateProcessor
- Inherits:
-
HamlTemplateProcessor
- Object
- HamlTemplateProcessor
- Brakeman::Haml6TemplateProcessor
- Defined in:
- lib/brakeman/processors/haml6_template_processor.rb
Constant Summary collapse
- OUTPUT_BUFFER =
s(:ivar, :@output_buffer)
- HAML_UTILS =
s(:colon2, s(:colon3, :Haml), :Util)
- HAML_UTILS2 =
s(:colon2, s(:const, :Haml), :Util)
- AV_SAFE_BUFFER =
s(:or, s(:call, nil, :output_buffer), s(:call, s(:colon2, s(:const, :ActionView), :OutputBuffer), :new))
- EMBEDDED_FILTER =
s(:const, :BrakemanFilter)
Instance Method Summary collapse
- #buffer_append?(exp) ⇒ Boolean
-
#embedded_filter?(arg) ⇒ Boolean
Handle our "fake" embedded filters.
- #html_escaped?(call) ⇒ Boolean
-
#initialize ⇒ Haml6TemplateProcessor
constructor
A new instance of Haml6TemplateProcessor.
- #is_escaped?(exp) ⇒ Boolean
- #javascript_escaped?(call) ⇒ Boolean
- #normalize_output(arg) ⇒ Object
- #output_buffer?(exp) ⇒ Boolean
- #process_lasgn(exp) ⇒ Object
- #process_lvar(exp) ⇒ Object
Constructor Details
#initialize ⇒ Haml6TemplateProcessor
Returns a new instance of Haml6TemplateProcessor.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/brakeman/processors/haml6_template_processor.rb', line 12 def initialize(*) super # Because of how Haml 6 handles line breaks - # we have to track where _haml_compiler variables are assigned. # then change the line number of where they are output to where # they are assigned. # # Like this: # # ; _haml_compiler1 = (params[:x]; # ; ); @output_buffer.safe_concat((((::Haml::Util.escape_html_safe((_haml_compiler1))).to_s).to_s)); # # `_haml_compiler1` is output a line after it's assigned, # but the assignment matches the "real" line where it is output in the template. @compiler_assigns = {} end |
Instance Method Details
#buffer_append?(exp) ⇒ Boolean
31 32 33 34 35 |
# File 'lib/brakeman/processors/haml6_template_processor.rb', line 31 def buffer_append? exp call? exp and output_buffer? exp.target and exp.method == :safe_concat end |
#embedded_filter?(arg) ⇒ Boolean
Handle our "fake" embedded filters
89 90 91 |
# File 'lib/brakeman/processors/haml6_template_processor.rb', line 89 def arg call? arg and arg.method == :render and arg.target == EMBEDDED_FILTER end |
#html_escaped?(call) ⇒ Boolean
68 69 70 71 |
# File 'lib/brakeman/processors/haml6_template_processor.rb', line 68 def html_escaped? call (call.target == HAML_UTILS or call.target == HAML_UTILS2) and (call.method == :escape_html or call.method == :escape_html_safe) end |
#is_escaped?(exp) ⇒ Boolean
54 55 56 57 58 59 |
# File 'lib/brakeman/processors/haml6_template_processor.rb', line 54 def is_escaped? exp return unless call? exp html_escaped? exp or javascript_escaped? exp end |
#javascript_escaped?(call) ⇒ Boolean
61 62 63 64 65 66 |
# File 'lib/brakeman/processors/haml6_template_processor.rb', line 61 def javascript_escaped? call # TODO: Adding here to match existing behavior for HAML, # but really this is not safe and needs to be revisited call.method == :j or call.method == :escape_javascript end |
#normalize_output(arg) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/brakeman/processors/haml6_template_processor.rb', line 78 def normalize_output arg arg = super(arg) if arg super(arg.first_arg) else arg end end |
#output_buffer?(exp) ⇒ Boolean
73 74 75 76 |
# File 'lib/brakeman/processors/haml6_template_processor.rb', line 73 def output_buffer? exp exp == OUTPUT_BUFFER or exp == AV_SAFE_BUFFER end |
#process_lasgn(exp) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/brakeman/processors/haml6_template_processor.rb', line 37 def process_lasgn exp if exp.lhs.match?(/_haml_compiler\d+/) @compiler_assigns[exp.lhs] = exp.rhs ignore else exp end end |
#process_lvar(exp) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/brakeman/processors/haml6_template_processor.rb', line 46 def process_lvar exp if exp.value.match?(/_haml_compiler\d+/) exp = @compiler_assigns[exp.value] || exp end exp end |