A platform for community discussion. Free, open, simple.
FIX: Escape regex pattern variable before using it
Vinoth Kannan297e8aaf2e0c
diff --git a/lib/i18n/backend/discourse_i18n.rb b/lib/i18n/backend/discourse_i18n.rbindex fec8150c79f..553de8eb50e 100644--- a/lib/i18n/backend/discourse_i18n.rb+++ b/lib/i18n/backend/discourse_i18n.rb@@ -44,7 +44,7 @@ module I18nresults = {}fallbacks(locale).each do |fallback|- find_results(/#{query}/i, results, translations[fallback])+ find_results(/#{Regexp.escape(query)}/i, results, translations[fallback])endresultsdiff --git a/spec/components/discourse_i18n_spec.rb b/spec/components/discourse_i18n_spec.rbindex 72dfc368ce5..bf51e6e7251 100644--- a/spec/components/discourse_i18n_spec.rb+++ b/spec/components/discourse_i18n_spec.rb@@ -12,6 +12,7 @@ describe I18n::Backend::DiscourseI18n dobackend.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)')endafter do@@ -32,6 +33,7 @@ describe I18n::Backend::DiscourseI18n doexpect(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)')endit 'can return multiple results' do