Skip to content
Permalink
Browse files

AO3-3617 Make autocomplete handle uppercase accents. (#3084)

* AO3-3617 Make autocomplete handle uppercase accents.

* AO3-3617 One additional test.
  • Loading branch information
tickinginstant authored and sarken committed Oct 10, 2019
1 parent edc8b2a commit 4781d3913ffd0b7b58ebc191ef0c050ab06ff523
Showing with 59 additions and 4 deletions.
  1. +50 −0 features/other_a/autocomplete.feature
  2. +9 −4 lib/autocomplete_source.rb
@@ -91,6 +91,56 @@ Feature: Display autocomplete for tags
And the pseud autocomplete should not contain "funny"
And the pseud autocomplete should not contain "different_user (funny)"

@javascript
Scenario: Characters in a fandom with non-ASCII uppercase letters should appear in the autocomplete.

Given basic tags
And I am logged in
And a canonical character "Bear" in fandom "Østenfor sol og vestenfor måne"
And a canonical character "Beatrice" in fandom "Much Ado About Nothing"
And I go to the new work page

When I choose "Østenfor sol og vestenfor måne" from the "Fandoms" autocomplete
And I enter "Bea" in the "Characters" autocomplete field
Then I should see "Bear" in the autocomplete
But I should not see "Beatrice" in the autocomplete

@javascript
Scenario: Accented uppercase letters should appear in the autocomplete.

Given basic tags
And I am logged in
And a canonical character "Éowyn (Tolkien)"
And a canonical character "Tybalt (Rómeó és Júlia)"
And I go to the new work page

When I enter "é" in the "Characters" autocomplete field
Then I should see "Éowyn (Tolkien)" in the autocomplete
And I should see "Tybalt (Rómeó és Júlia)" in the autocomplete

@javascript
Scenario: Other non-ASCII uppercase letters should appear in the autocomplete.

Given basic tags
And I am logged in
And a canonical fandom "Østenfor sol og vestenfor måne"
And I go to the new work page

When I enter "ø" in the "Fandoms" autocomplete field
Then I should see "Østenfor sol og vestenfor måne" in the autocomplete

@javascript
Scenario: Characters with a non-ASCII uppercase letter will appear in fandom-specific autocompletes.

Given basic tags
And I am logged in
And a canonical character "Éowyn" in fandom "Lord of the Rings"
And I go to the new work page

When I choose "Lord of the Rings" from the "Fandoms" autocomplete
And I enter "É" in the "Characters" autocomplete field
Then I should see "Éowyn" in the autocomplete

@javascript
Scenario: Search terms are highlighted in autocomplete results
Given I am logged in
@@ -82,7 +82,7 @@ def get_search_regex(search_param)
# and returns an array of stripped and lowercase words for actual searching or use in keys
def get_search_terms(search_term)
terms = search_term.is_a?(Array) ? search_term.map {|term| term.split(',')}.flatten : (search_term.blank? ? [] : search_term.split(','))
terms.map {|term| term.strip.downcase}
terms.map { |term| term.strip.downcase }
end

def parse_autocomplete_value(current_autocomplete_value)
@@ -218,11 +218,16 @@ def autocomplete_cache_key(autocomplete_prefix, search_param)
autocomplete_prefix + "_" + AUTOCOMPLETE_CACHE_KEY + "_" + search_param
end

# split into words
# Split a string into words.
def autocomplete_phrase_split(string)
# split on one or more spaces, ampersand, slash, double quotation mark,
# Use the ActiveSupport::Multibyte::Chars class to handle downcasing
# instead of the basic string class, because it can handle downcasing
# letters with accents or other diacritics.
normalized = string.mb_chars.downcase.to_s

# Split on one or more spaces, ampersand, slash, double quotation mark,
# opening parenthesis, closing parenthesis (just in case), tilde, hyphen
string.downcase.split(/(?:\s+|\&|\/|"|\(|\)|\~|-)/).reject(&:blank?)
normalized.split(/(?:\s+|\&|\/|"|\(|\)|\~|-)/).reject(&:blank?)
end

def autocomplete_pieces(string)

0 comments on commit 4781d39

Please sign in to comment.
You can’t perform that action at this time.