Skip to content

Commit 95e64bb

Browse files
authored
Add failing specs for inter-token comments in merge_strings (#742)
2 parents 535c167 + ad22121 commit 95e64bb

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

spec/ios_l10n_helper_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,44 @@ def file_encoding(path)
122122
end
123123
end
124124

125+
it 'prefixes keys when `.strings` comments sit between a statement\'s tokens' do
126+
# Regression: the duplicate-key scanner accepts comments *between* a statement's tokens (e.g.
127+
# `CFBundleName /* c */ = WordPress;`), and bookkeeping derives keys from `plutil`, which agrees.
128+
# But the line-based rewrite only prefixes when `=` and the value are adjacent, so an inter-token
129+
# comment leaves the key written unprefixed while still bookkept *with* the prefix — the exact
130+
# collision/inconsistent-output the prefix exists to prevent.
131+
content = <<~STRINGS
132+
CFBundleName = WordPress /* trailing */;
133+
AppName /* between key and = */ = WordPress;
134+
DisplayName /* between key and = */ = "WordPress";
135+
STRINGS
136+
Dir.mktmpdir('a8c-release-toolkit-l10n-helper-tests-') do |tmp_dir|
137+
input_file = File.join(tmp_dir, 'InfoPlist.strings')
138+
File.write(input_file, content)
139+
output_file = File.join(tmp_dir, 'output.strings')
140+
described_class.merge_strings(paths: { input_file => 'pfx.' }, output_path: output_file)
141+
merged_keys = described_class.read_strings_file_as_hash(path: output_file).keys
142+
expect(merged_keys).to contain_exactly('pfx.CFBundleName', 'pfx.AppName', 'pfx.DisplayName')
143+
end
144+
end
145+
146+
it 'does not silently drop a key to a collision when an inter-token comment blocks prefixing' do
147+
# The harm of the gap above: two files each carrying the same key behind an inter-token comment are
148+
# bookkept under distinct prefixes (so no duplicate is reported), yet both are written verbatim —
149+
# producing a genuine duplicate in the merged file that `plutil` later collapses to a single value.
150+
content = "CFBundleName /* c */ = WordPress;\n"
151+
Dir.mktmpdir('a8c-release-toolkit-l10n-helper-tests-') do |tmp_dir|
152+
file_a = File.join(tmp_dir, 'A.strings')
153+
file_b = File.join(tmp_dir, 'B.strings')
154+
File.write(file_a, content)
155+
File.write(file_b, content)
156+
output_file = File.join(tmp_dir, 'output.strings')
157+
described_class.merge_strings(paths: { file_a => 'a.', file_b => 'b.' }, output_path: output_file)
158+
merged_keys = described_class.read_strings_file_as_hash(path: output_file).keys
159+
expect(merged_keys).to contain_exactly('a.CFBundleName', 'b.CFBundleName')
160+
end
161+
end
162+
125163
it 'returns duplicate keys found' do
126164
paths = { fixture('Localizable-utf16.strings') => nil, fixture('non-latin-utf16.strings') => nil }
127165
Dir.mktmpdir('a8c-release-toolkit-l10n-helper-tests-') do |tmp_dir|

0 commit comments

Comments
 (0)