Skip to content

Commit

Permalink
- Fix ruby-parse with a folder ending in .rb (#1047)
Browse files Browse the repository at this point in the history
It's just checking that the path ends with `.rb`, which can happen with folders
  • Loading branch information
Earlopain authored Dec 17, 2024
1 parent 9a6ee63 commit 510eba0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/parser/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,12 @@ def process_fragments

def process_files
@files.each do |filename|
source = File.read(filename).force_encoding(@parser.default_encoding)
source = begin
File.read(filename).force_encoding(@parser.default_encoding)
rescue Errno::EISDIR
# Will happen for a folder called `foo.rb`. Just catch this here, it's cheaper than checking every file.
next
end

buffer = Parser::Source::Buffer.new(filename)

Expand Down
9 changes: 9 additions & 0 deletions test/test_runner_parse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,13 @@ def test_stdin_input
assert_prints ['--emit-ruby', '-', { stdin_data: '123' }],
's(:int, 123)'
end

def test_folder_with_rb_extension
Dir.mktmpdir do |tmp_dir|
Dir.mkdir("#{tmp_dir}/foo.rb")
File.write("#{tmp_dir}/foo.rb/bar.rb", "123")

assert_prints [tmp_dir], '(int 123)'
end
end
end

0 comments on commit 510eba0

Please sign in to comment.