Skip to content
This repository was archived by the owner on Apr 23, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions lib/ruby_ast_gen/erb_to_ruby_transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
class ErbToRubyTransformer
def initialize
@parser = Temple::ERB::Parser.new
@ruby_parser_buffer = Parser::Source::Buffer.new("internal_tmp")
@ruby_parser = Parser::CurrentRuby.new
@in_control_block = false
@output_tmp_var = "joern__buffer"
@in_do_block = false
Expand Down Expand Up @@ -53,14 +51,21 @@ def visit(node)
inner_node = node[2]
code = inner_node[1].to_s

if code.include?(" if ")
@ruby_parser_buffer.source = code
ast = @ruby_parser.parse(@ruby_parser_buffer)
if code.include?(" if ") || code.include?("unless")
parser_buffer = Parser::Source::Buffer.new("internal_tmp_#{Time.now.nsec}")
parser_buffer.source = code
ruby_parser = Parser::CurrentRuby.new
ast = ruby_parser.parse(parser_buffer)
if ast.is_a?(::Parser::AST::Node)
case ast.type
when :if
call, if_cond = code.split(" if ")
@output << "if #{if_cond}"
if code.include?(" if ")
call, if_cond = code.split(" if ")
@output << "if #{if_cond}"
else
call, if_cond = code.split(" unless ")
@output << "unless #{if_cond}"
end
template_call = if escape_enabled then "joern__template_out_raw" else "joern__template_out_escape" end
@output << "#{@output_tmp_var} << #{template_call}(#{call})"
@output << "end"
Expand Down