From b215d2112d8da07bff5f47fd53a52a5e4026cd7c Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 12 Aug 2017 17:15:19 -0500 Subject: [PATCH] wiki pages: normalize unicode in other names. --- app/models/wiki_page.rb | 2 +- test/unit/wiki_page_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 28c3e399d..7b1c742ba 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -170,7 +170,7 @@ class WikiPage < ApplicationRecord end def normalize_other_names - normalized_other_names = other_names.to_s.gsub(/\u3000/, " ").scan(/\S+/) + normalized_other_names = other_names.to_s.unicode_normalize(:nfkc).scan(/[^[:space:]]+/) self.other_names = normalized_other_names.uniq.join(" ") end diff --git a/test/unit/wiki_page_test.rb b/test/unit/wiki_page_test.rb index cadcbe57b..7a1f2d933 100644 --- a/test/unit/wiki_page_test.rb +++ b/test/unit/wiki_page_test.rb @@ -61,6 +61,11 @@ class WikiPageTest < ActiveSupport::TestCase assert_equal("hot_potato", @wiki_page.title) end + should "normalize its other names" do + @wiki_page.update(:other_names => "foo*bar baz baz 加賀(艦これ)") + assert(%w[foo*bar baz 加賀(艦これ)], @wiki_page.other_names_array) + end + should "search by title" do matches = WikiPage.titled("hot potato") assert_equal(1, matches.count)