FIX: Escape regex pattern variable before using it
This commit is contained in:
parent
c6f339a0b5
commit
297e8aaf2e
|
@ -44,7 +44,7 @@ module I18n
|
|||
results = {}
|
||||
|
||||
fallbacks(locale).each do |fallback|
|
||||
find_results(/#{query}/i, results, translations[fallback])
|
||||
find_results(/#{Regexp.escape(query)}/i, results, translations[fallback])
|
||||
end
|
||||
|
||||
results
|
||||
|
|
|
@ -12,6 +12,7 @@ describe I18n::Backend::DiscourseI18n do
|
|||
backend.store_translations(:en, items: { one: 'one item', other: "%{count} items" })
|
||||
backend.store_translations(:de, bar: 'Bar in :de')
|
||||
backend.store_translations(:ru, baz: 'Baz in :ru')
|
||||
backend.store_translations(:en, link: '[text](url)')
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -32,6 +33,7 @@ describe I18n::Backend::DiscourseI18n do
|
|||
expect(backend.search(:en, 'Foo')).to eq('foo' => 'Foo in :en')
|
||||
expect(backend.search(:en, 'hello')).to eq('wat' => 'Hello %{count}')
|
||||
expect(backend.search(:en, 'items.one')).to eq('items.one' => 'one item')
|
||||
expect(backend.search(:en, '](')).to eq('link' => '[text](url)')
|
||||
end
|
||||
|
||||
it 'can return multiple results' do
|
||||
|
|
Loading…
Reference in New Issue