Skip to content

Commit fb08c6c

Browse files
committed
Fix processing of utf-8 files
Fixes #1517
1 parent b127c8f commit fb08c6c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/yard/parser/source_parser.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def parse(paths = DEFAULT_PATH_GLOB, excluded = [], level = log.level)
107107
files = [paths].flatten.
108108
map {|p| File.directory?(p) ? "#{p}/**/*.{rb,c,cc,cxx,cpp}" : p }.
109109
map {|p| p.include?("*") ? Dir[p].sort_by {|d| [d.length, d] } : p }.flatten.
110-
reject {|p| !File.file?(p) || excluded.any? {|re| p =~ re } }
110+
reject {|p| !File.file?(p) || excluded.any? {|re| p =~ re } }.
111+
map {|p| p.encoding == Encoding.default_external ? p : p.dup.force_encoding(Encoding.default_external) }
111112

112113
log.enter_level(level) do
113114
parse_in_order(*files.uniq)

spec/parser/source_parser_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,15 @@ class Foo < Bar
499499
YARD.parse ['foo']
500500
end
501501

502+
it "converts globs into UTF-8" do
503+
expect(Dir).to receive(:[]).with('lib/**/*.rb').and_return(['lib/é.rb'])
504+
expect(File).to receive(:file?).with('lib/é.rb').and_return(true)
505+
expect(File).to receive(:read_binary).with('lib/é.rb').and_return("class A; end")
506+
507+
YARD.parse ['lib/**/*.rb']
508+
expect(Registry.at('A')).not_to be nil
509+
end
510+
502511
it "uses Registry.checksums cache if file is cached" do
503512
data = 'DATA'
504513
hash = Registry.checksum_for(data)

0 commit comments

Comments
 (0)