Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 0.5.1 (Next)

* [#45](https://github.com/dblock/fui/pull/45): Migrated from Travis CI to GitHub Actions with danger-pr-comment workflow - [@dblock](https://github.com/dblock).
* [#37](https://github.com/dblock/fui/issues/37): Fixed `ArgumentError: invalid byte sequence in UTF-8` when processing files with non-UTF-8 encoding - [@dblock](https://github.com/dblock).
* Your contribution here.

### 0.5.0 (2018/12/19)
Expand Down
29 changes: 13 additions & 16 deletions lib/fui/finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,23 @@ def global_imported(file_contents, header)
end

def process_code(references, path)
File.open(path) do |file|
yield path if block_given?
headers.each do |header|
filename_without_extension = File.basename(path, File.extname(path))
file_contents = File.read(file)
global_import_exists = global_imported(file_contents, header)
local_import_exists = local_imported(file_contents, header)
references[header] << path if filename_without_extension != header.filename_without_extension && (local_import_exists || global_import_exists)
end
yield path if block_given?
file_contents = File.read(path, encoding: 'binary').encode('UTF-8', invalid: :replace, undef: :replace)
headers.each do |header|
filename_without_extension = File.basename(path, File.extname(path))
global_import_exists = global_imported(file_contents, header)
local_import_exists = local_imported(file_contents, header)
references[header] << path if filename_without_extension != header.filename_without_extension && (local_import_exists || global_import_exists)
end
end

def process_xml(references, path)
File.open(path) do |file|
yield path if block_given?
headers.each do |header|
filename_without_extension = File.basename(path, File.extname(path))
check_xibs = !options['ignore-xib-files']
references[header] << path if (check_xibs || filename_without_extension != header.filename_without_extension) && File.read(file).include?("customClass=\"#{header.filename_without_extension}\"")
end
yield path if block_given?
file_contents = File.read(path, encoding: 'binary').encode('UTF-8', invalid: :replace, undef: :replace)
headers.each do |header|
filename_without_extension = File.basename(path, File.extname(path))
check_xibs = !options['ignore-xib-files']
references[header] << path if (check_xibs || filename_without_extension != header.filename_without_extension) && file_contents.include?("customClass=\"#{header.filename_without_extension}\"")
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/non_utf8/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#import "used_class.h"
// ÄãºÃ
- void main() {}
8 changes: 8 additions & 0 deletions spec/fixtures/non_utf8/used_class.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// UsedClass.h
//

#import <UIKit/UIKit.h>

@interface UsedClass
@end
15 changes: 15 additions & 0 deletions spec/fui/finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,19 @@
end
end
end
context 'files with non-UTF-8 encoding' do
before :each do
@fixtures_dir = File.expand_path(File.join(__FILE__, '../../fixtures/non_utf8'))
end
describe '#references' do
it 'handles non-UTF-8 encoded files without raising an error' do
finder = Fui::Finder.new(@fixtures_dir)
expect { finder.references }.not_to raise_error
end
it 'finds references in files with non-UTF-8 encoding' do
finder = Fui::Finder.new(@fixtures_dir)
expect(Hash[finder.references.map { |k, v| [k.filename, v.count] }]).to eq('used_class.h' => 1)
end
end
end
end
Loading