Skip to content

Commit 84f3abc

Browse files
authored
Merge pull request #184 from prograils/fix/quote_regex_in_hash_storage
Add quote to regex in hash storage
2 parents a20ec35 + 083e736 commit 84f3abc

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/lit/adapters/hash_storage.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def subtree_of_key(key)
3434
end
3535

3636
def subtree_keys(key)
37-
keys.select { |k| k.match?(/\A#{key}*/) }
37+
keys.select { |k| k.match?(/\A#{Regexp.quote(key)}*/) }
3838
end
3939

4040
def form_cache_localizations(keys_of_subtree)

test/unit/lit_behaviour_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,17 @@ def teardown
264264
assert_equal find_localization_for('interpolated_key', :en).default_value, 'Candidate %{name}'
265265
end
266266

267+
test 'it does not break on simple form/complicated keys when using regex in hash storage' do
268+
prev_kv_engine = Lit.key_value_engine
269+
Lit.key_value_engine = 'hash'
270+
key = 'helpers.label.meta_signings.contract_signings_attributes][0]' \
271+
'[contract_documents.contract]'
272+
result = I18n.t(key, default: 'Contract')
273+
assert_equal result, 'Contract'
274+
assert_equal find_localization_for(key, :en).default_value, 'Contract'
275+
Lit.key_value_engine = prev_kv_engine
276+
end
277+
267278
private
268279

269280
def find_localization_for(key, locale)

0 commit comments

Comments
 (0)