mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: skip invalid URLs when checking for audio/video in search blurbs
Fixes 500 errors on search queries introduced in 580a4a8
This commit is contained in:
parent
b869ef8a76
commit
0dfc594784
@ -78,13 +78,15 @@ class Search
|
||||
|
||||
urls = Set.new
|
||||
cooked.scan(URI.regexp(%w{http https})) { urls << $& }
|
||||
|
||||
urls.each do |url|
|
||||
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"))
|
||||
begin
|
||||
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
|
||||
rescue URI::InvalidURIError
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -28,7 +28,7 @@ describe Search do
|
||||
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")}")
|
||||
end
|
||||
|
||||
it "strips URLs correctly when blurb is" do
|
||||
it "strips URLs correctly when blurb is longer than limit" do
|
||||
cooked = <<~RAW
|
||||
Here goes a test cooked with enough characters to hit the blurb limit.
|
||||
|
||||
@ -41,6 +41,13 @@ describe Search do
|
||||
expect(result).to eq("Here goes a test cooked with enough characters to hit the blurb limit. Something is very interesting about this audio file. #{I18n.t("search.audio")}")
|
||||
end
|
||||
|
||||
it "does not fail on bad URLs" do
|
||||
cooked = <<~RAW
|
||||
invalid URL: http:error] should not trip up blurb generation.
|
||||
RAW
|
||||
result = Search::GroupedSearchResults.blurb_for(cooked)
|
||||
expect(result).to eq("invalid URL: http:error] should not trip up blurb generation.")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user