From d9092ea3451e806cf18496c58b0b5142b4ac30fb Mon Sep 17 00:00:00 2001 From: Chad Nelson Date: Wed, 16 Sep 2020 13:48:59 -0400 Subject: [PATCH] Parse out empty params from queries If an empty param,`()`, is included in a query, the boolen query parser included from advanced search gem throws an error. It is documented as an issue upstream at https://github.com/projectblacklight/blacklight_advanced_search/issues/101, but at the moment no fix upstream is proposed. This PR works around the issue by removing empty parens from the query string. It does not impact parens containing content. --- app/models/search_builder.rb | 2 +- spec/models/search_builder_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/search_builder.rb b/app/models/search_builder.rb index 1851854ce..dcc2a2391 100644 --- a/app/models/search_builder.rb +++ b/app/models/search_builder.rb @@ -106,7 +106,7 @@ def process_is(value, op) end def substitute_special_chars(value, _) - value.gsub(/[:?]/, " ") rescue value + value.gsub(/([:?]|\(\))/, " ") rescue value end def no_journals(solr_parameters) diff --git a/spec/models/search_builder_spec.rb b/spec/models/search_builder_spec.rb index 9123bfcbf..2eceb7a6c 100644 --- a/spec/models/search_builder_spec.rb +++ b/spec/models/search_builder_spec.rb @@ -183,6 +183,14 @@ # @see BL-1301 for ref. Basically Solr treats ? as a special character. expect(subject.substitute_special_chars("foo bar?", nil)).to eq("foo bar ") end + + it "substitutes empty parens '()' " do + expect(subject.substitute_special_chars("foo () bar", nil)).to eq("foo bar") + end + + it "does not substitutes parens containing values " do + expect(subject.substitute_special_chars("foo (bar) baz", nil)).to eq("foo (bar) baz") + end end describe "#blacklight_params" do