Skip to content

Commit 083e736

Browse files
committed
Add quote to regex in hash storage
1 parent 3b8db97 commit 083e736

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/lit/adapters/hash_storage.rb

+1-1
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

+11
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)