Skip to content

Commit

Permalink
Fix processing of utf-8 files
Browse files Browse the repository at this point in the history
Fixes #1517
  • Loading branch information
lsegal committed Sep 3, 2024
1 parent b127c8f commit fb08c6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/yard/parser/source_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def parse(paths = DEFAULT_PATH_GLOB, excluded = [], level = log.level)
files = [paths].flatten.
map {|p| File.directory?(p) ? "#{p}/**/*.{rb,c,cc,cxx,cpp}" : p }.
map {|p| p.include?("*") ? Dir[p].sort_by {|d| [d.length, d] } : p }.flatten.
reject {|p| !File.file?(p) || excluded.any? {|re| p =~ re } }
reject {|p| !File.file?(p) || excluded.any? {|re| p =~ re } }.
map {|p| p.encoding == Encoding.default_external ? p : p.dup.force_encoding(Encoding.default_external) }

log.enter_level(level) do
parse_in_order(*files.uniq)
Expand Down
9 changes: 9 additions & 0 deletions spec/parser/source_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,15 @@ class Foo < Bar
YARD.parse ['foo']
end

it "converts globs into UTF-8" do
expect(Dir).to receive(:[]).with('lib/**/*.rb').and_return(['lib/é.rb'])
expect(File).to receive(:file?).with('lib/é.rb').and_return(true)
expect(File).to receive(:read_binary).with('lib/é.rb').and_return("class A; end")

YARD.parse ['lib/**/*.rb']
expect(Registry.at('A')).not_to be nil
end

it "uses Registry.checksums cache if file is cached" do
data = 'DATA'
hash = Registry.checksum_for(data)
Expand Down

0 comments on commit fb08c6c

Please sign in to comment.