Skip to content

Commit 06d5a33

Browse files
committed
Swap the fixture for "invalid" case from PNG to plain text
h/t @mokagio in #329 (comment)
1 parent 0354867 commit 06d5a33

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_helper.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ class L10nHelper
1818
# - `nil` if the file does not exist or is neither of those format (e.g. not a `.strings` file at all)
1919
#
2020
def self.strings_file_type(path:)
21-
format_desc, status = Open3.capture2('file', path)
21+
# Start by checking it seems like a valid property-list file (and not e.g. an image or plain text file)
22+
_, status = Open3.capture2('/usr/bin/plutil', '-lint', path)
23+
return nil unless status.success?
24+
25+
# If it is a valid property-list file, determine the actual format used
26+
format_desc, status = Open3.capture2('/usr/bin/file', path)
2227
return nil unless status.success?
2328

2429
case format_desc

spec/ios_l10n_helper_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def file_encoding(path)
3333
end
3434

3535
it 'returns nil on file that is not a strings file at all' do
36-
png_fixture = fixture('not-a-strings-file.png')
37-
expect(File).to exist(png_fixture)
38-
expect(described_class.strings_file_type(path: '/invalid-path')).to be_nil
36+
invalid_fixture = fixture('invalid-file.strings')
37+
expect(File).to exist(invalid_fixture)
38+
expect(described_class.strings_file_type(path: invalid_fixture)).to be_nil
3939
end
4040
end
4141

@@ -117,7 +117,7 @@ def file_encoding(path)
117117
end
118118

119119
it 'raises if trying to parse an invalid strings file' do
120-
file = fixture('not-a-strings-file.png')
120+
file = fixture('invalid-file.strings')
121121
expect do
122122
described_class.read_strings_file_as_hash(path: file)
123123
end.to raise_exception(RuntimeError)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Contrary to what the extension of this file suggests, this is not a `.strings` file.
2+
Instead, this is just a regular, plain text file, which should be detected as invalid
3+
if provided as an input to `Ios::L10nHelper` methods.
Binary file not shown.

0 commit comments

Comments
 (0)