Fix #5194: AND/OR no longer trigger autocomplete.

Also change the /autocomplete.json API to no longer strip '-' and '~'
from the start of the tag. This may be a breaking change if third-party
scripts relied on this behavior.
This commit is contained in:
evazion
2022-08-25 20:41:42 -05:00
parent 9eb31c8018
commit 115085006e
2 changed files with 11 additions and 11 deletions

View File

@@ -79,17 +79,12 @@ class AutocompleteService
#
# @return [Array<Hash>] the autocomplete results
def autocomplete_tag_query
if parsed_query.tag_names.one?
tag = parsed_query.tag_names.first
autocomplete_tag(tag)
elsif parsed_query.wildcards.one?
wildcard = parsed_query.wildcards.first
autocomplete_tag(wildcard.name)
elsif parsed_query.metatags.one?
if parsed_query.metatags.one?
metatag = parsed_query.metatags.first
autocomplete_metatag(metatag.name, metatag.value)
else
[]
tag = Tag.normalize_name(query)
autocomplete_tag(tag)
end
end
@@ -351,7 +346,7 @@ class AutocompleteService
end
def parsed_query
PostQuery.new(query.delete_prefix("-").delete_prefix("~"))
PostQuery.new(query)
end
memoize :autocomplete_results, :parsed_query

View File

@@ -16,6 +16,8 @@ class AutocompleteControllerTest < ActionDispatch::IntegrationTest
context "index action" do
setup do
create(:tag, name: "azur_lane")
create(:tag, name: "android")
create(:tag, name: "original")
end
should "work for opensearch queries" do
@@ -27,8 +29,6 @@ class AutocompleteControllerTest < ActionDispatch::IntegrationTest
should "work for tag queries" do
assert_autocomplete_equals(["azur_lane"], "azur", "tag_query")
assert_autocomplete_equals(["azur_lane"], "-azur", "tag_query")
assert_autocomplete_equals(["azur_lane"], "~azur", "tag_query")
assert_autocomplete_equals(["azur_lane"], "AZUR", "tag_query")
assert_autocomplete_equals(["rating:sensitive"], "rating:s", "tag_query")
@@ -42,6 +42,11 @@ class AutocompleteControllerTest < ActionDispatch::IntegrationTest
assert_equal([], response.parsed_body)
end
should "work for the AND and OR keywords" do
assert_autocomplete_equals(["android"], "and", "tag_query")
assert_autocomplete_equals(["original"], "or", "tag_query")
end
should "not set session cookies when the response is publicly cached" do
get autocomplete_index_path(search: { query: "azur", type: "tag_query" }), as: :json