Skip to content

Commit

Permalink
AO3-4735 Don't treat "-" as NOT when it is alone
Browse files Browse the repository at this point in the history
  • Loading branch information
potpotkettle committed Sep 28, 2024
1 parent f607097 commit b7ab976
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/search/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def split_query_text_words(fieldname, text)
str = ""
return str if text.blank?
text.split(" ").each do |word|
if word[0] == "-"
if word.length >= 2 && word[0] == "-"
str << " NOT"
word.slice!(0)
end
Expand Down
6 changes: 6 additions & 0 deletions spec/models/search/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@
result = q.split_query_text_words(:hero, "superman -batman")
expect(result).to eq(" hero:superman NOT hero:batman")
end

it "should not touch stand-alone minuses" do
q = Query.new
result = q.split_query_text_words(:title, "foo - bar")
expect(result).to eq(" title:foo title:\\- title:bar")
end
end
end

0 comments on commit b7ab976

Please sign in to comment.