Class: Brakeman::Haml6TemplateProcessor
- Inherits:
-
HamlTemplateProcessor
- Object
- SexpProcessor
- BaseProcessor
- TemplateProcessor
- 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)
Constants inherited from HamlTemplateProcessor
Brakeman::HamlTemplateProcessor::ATTRIBUTE_BUILDER, Brakeman::HamlTemplateProcessor::COFFEE_FILTER, Brakeman::HamlTemplateProcessor::ESCAPE_METHODS, Brakeman::HamlTemplateProcessor::HAMLOUT, Brakeman::HamlTemplateProcessor::HAML_BUFFER, Brakeman::HamlTemplateProcessor::HAML_HELPERS, Brakeman::HamlTemplateProcessor::HAML_HELPERS2, Brakeman::HamlTemplateProcessor::JAVASCRIPT_FILTER, Brakeman::HamlTemplateProcessor::PRESERVE_METHODS
Constants inherited from BaseProcessor
Constants included from Util
Util::ALL_COOKIES, Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::DIR_CONST, Util::LITERALS, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_COOKIES, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::REQUEST_REQUEST_PARAMETERS, Util::SAFE_LITERAL, Util::SESSION, Util::SESSION_SEXP, Util::SIMPLE_LITERALS
Constants inherited from SexpProcessor
Instance Attribute Summary
Attributes inherited from SexpProcessor
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
Methods inherited from HamlTemplateProcessor
#build_output_from_push_text, #find_and_preserve?, #fix_textareas?, #get_pushed_value, #haml_attribute_builder?, #haml_helpers?, #hamlout_attributes?, #process_block, #process_call, #raw?
Methods inherited from TemplateProcessor
#add_escaped_output, #add_output, #process, #process_escaped_output, #process_output
Methods inherited from BaseProcessor
#find_render_type, #ignore, #make_inline_render, #make_render, #make_render_in_view, #process_arglist, #process_attrasgn, #process_block, #process_cdecl, #process_default, #process_dstr, #process_evstr, #process_file, #process_hash, #process_if, #process_ignore, #process_iter, #process_scope
Methods included from Util
#all_literals?, #array?, #block?, #call?, #camelize, #class_name, #constant?, #contains_class?, #cookies?, #dir_glob?, #false?, #hash?, #hash_access, #hash_insert, #hash_iterate, #hash_values, #integer?, #kwsplat?, #literal?, #make_call, #node_type?, #number?, #params?, #pluralize, #rails_version, #recurse_check?, #regexp?, #remove_kwsplat, #request_headers?, #request_value?, #result?, #safe_literal, #safe_literal?, #safe_literal_target?, #set_env_defaults, #sexp?, #simple_literal?, #string?, #string_interp?, #symbol?, #template_path_to_name, #true?, #underscore
Methods included from ProcessorHelper
#current_file, #process_all, #process_all!, #process_call_args, #process_call_defn?, #process_class, #process_module
Methods inherited from SexpProcessor
#in_context, #process, processors, #scope
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 |