mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 19:33:44 +08:00
FIX: Don’t raise on some search terms
Currently, when certain search terms are provided, this can lead to `Search.need_segmenting?` raising an error because it makes `URI#path` to return `nil` instead of a string. This patch forces a cast to string so it won’t raise anymore.
This commit is contained in:
parent
e68748318e
commit
fe1098ebac
|
@ -228,7 +228,7 @@ class Search
|
||||||
|
|
||||||
def self.need_segmenting?(data)
|
def self.need_segmenting?(data)
|
||||||
return false if data.match?(/\A\d+\z/)
|
return false if data.match?(/\A\d+\z/)
|
||||||
!URI.parse(data).path.start_with?("/")
|
!URI.parse(data).path.to_s.start_with?("/")
|
||||||
rescue URI::InvalidURIError
|
rescue URI::InvalidURIError
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,6 +31,14 @@ RSpec.describe Search do
|
||||||
it { is_expected.not_to be_need_segmenting(data) }
|
it { is_expected.not_to be_need_segmenting(data) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when data makes `URI#path` return `nil`" do
|
||||||
|
let(:data) { "in:solved%20category:50%20order:likes" }
|
||||||
|
|
||||||
|
it "doesn’t raise an error" do
|
||||||
|
expect { search.need_segmenting?(data) }.not_to raise_error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "when data is something else" do
|
context "when data is something else" do
|
||||||
let(:data) { "text" }
|
let(:data) { "text" }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user