autocomplete: fix exception when typing "/" in autocomplete.

Fix an exception that could occur when typing "/" by itself in
autocomplete and a regular tag starting with "/" was returned. This
caused an exception in `r[:antecedent].length` because the tag's
antecedent was nil.
This commit is contained in:
evazion
2020-12-14 21:57:28 -06:00
parent 4cdaf7bcdf
commit 26246b0ac9
2 changed files with 25 additions and 12 deletions

View File

@@ -69,7 +69,8 @@ class AutocompleteService
string = string + "*" unless string.include?("*")
results = tag_matches(string)
results += tag_abbreviation_matches(string)
results = results.uniq.sort_by { |r| [r[:antecedent].length, -r[:post_count]] }.take(limit)
results = results.sort_by { |r| [r[:antecedent].to_s.size, -r[:post_count]] }
results = results.uniq { |r| r[:value] }.take(limit)
elsif string.include?("*")
results = tag_matches(string)
results = tag_other_name_matches(string) if results.blank?