Skip to content

Commit

Permalink
Ensure RubyParser is passed path as a string
Browse files Browse the repository at this point in the history
Fixes #1534
  • Loading branch information
presidentbeef committed Dec 23, 2020
1 parent f09d161 commit c73f314
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/brakeman/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ def read_files list, type
end
end

# _path_ can be a string or a Brakeman::FilePath
def parse_ruby input, path
if path.is_a? Brakeman::FilePath
path = path.relative
end

begin
Brakeman.debug "Parsing #{path}"
RubyParser.new.parse input, path, @timeout
Expand Down
10 changes: 10 additions & 0 deletions test/tests/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,14 @@ def test_parse_error_shows_newer_failure
assert_match(/parse error on value \"\$end\" \(\$end\)/, @tracker.errors.first[:error])
end
end

def test_parse_ruby_accepts_file_path
file_path = Brakeman::FilePath.from_app_tree @tracker.app_tree, "config/test.rb"

parsed = @file_parser.parse_ruby <<-'RUBY', file_path
"#{__FILE__}"
RUBY

assert_equal s(:str, "config/test.rb"), parsed
end
end

0 comments on commit c73f314

Please sign in to comment.