diff --git a/lib/oneboxer.rb b/lib/oneboxer.rb
index 871e48c96e5..c77857ad574 100644
--- a/lib/oneboxer.rb
+++ b/lib/oneboxer.rb
@@ -6,6 +6,8 @@ Dir["#{Rails.root}/lib/onebox/engine/*_onebox.rb"].sort.each { |f| require f }
module Oneboxer
ONEBOX_CSS_CLASS = "onebox"
+ AUDIO_REGEX = /^\.(mp3|og[ga]|opus|wav|m4[abpr]|aac|flac)$/i
+ VIDEO_REGEX = /^\.(mov|mp4|m4v|webm|ogv|3gp)$/i
# keep reloaders happy
unless defined? Oneboxer::Result
@@ -171,9 +173,9 @@ module Oneboxer
def self.local_upload_html(url)
case File.extname(URI(url).path || "")
- when /^\.(mov|mp4|m4v|webm|ogv|3gp)$/i
+ when VIDEO_REGEX
""
- when /^\.(mp3|og[ga]|opus|wav|m4[abpr]|aac|flac)$/i
+ when AUDIO_REGEX
""
end
end
diff --git a/lib/search/grouped_search_results.rb b/lib/search/grouped_search_results.rb
index eb3454c9759..4a5dcccf179 100644
--- a/lib/search/grouped_search_results.rb
+++ b/lib/search/grouped_search_results.rb
@@ -80,8 +80,12 @@ class Search
cooked.scan(URI.regexp(%w{http https})) { urls << $& }
urls.each do |url|
- cooked.gsub!(url, I18n.t("search.video")) if url.match(/.(mov|mp4|webm|ogv)/)
- cooked.gsub!(url, I18n.t("search.audio")) if url.match(/.(mp3|ogg|wav|m4a)/)
+ case File.extname(URI(url).path || "")
+ when Oneboxer::VIDEO_REGEX
+ cooked.gsub!(url, I18n.t("search.video"))
+ when Oneboxer::AUDIO_REGEX
+ cooked.gsub!(url, I18n.t("search.audio"))
+ end
end
if term
diff --git a/spec/lib/search_spec.rb b/spec/lib/search_spec.rb
index e78f75faf44..c3aaa881300 100644
--- a/spec/lib/search_spec.rb
+++ b/spec/lib/search_spec.rb
@@ -22,7 +22,7 @@ describe Search do
link to an audio file: https://somesite.com/content/file123.m4a
- link to a video file: https://somesite.com/content/somethingelse.mov
+ link to a video file: https://somesite.com/content/somethingelse.MOV
RAW
result = Search::GroupedSearchResults.blurb_for(cooked)
expect(result).to eq("link to an external page: https://google.com/?u=bar link to an audio file: #{I18n.t("search.audio")} link to a video file: #{I18n.t("search.video")}")