Skip to content

A platform for community discussion. Free, open, simple.

FIX: Don’t raise on some search terms

Loïc Guitautfe1098ebac85
diff --git a/lib/search.rb b/lib/search.rb
index 093da16ab6c..05cd3653607 100644
--- a/lib/search.rb
+++ b/lib/search.rb
@@ -228,7 +228,7 @@ class Search
def self.need_segmenting?(data)
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
true
end
diff --git a/spec/lib/search_spec.rb b/spec/lib/search_spec.rb
index 0e73dd9a260..51ad9cd6851 100644
--- a/spec/lib/search_spec.rb
+++ b/spec/lib/search_spec.rb
@@ -31,6 +31,14 @@ RSpec.describe Search do
it { is_expected.not_to be_need_segmenting(data) }
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
let(:data) { "text" }