From 7fbac34962091129371ed3a4152c57b267ea2674 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 9 Jan 2021 18:42:33 -0600 Subject: [PATCH] wiki pages: fix normalization of wiki page title. Fix the wiki page title "azur___lane" being normalized to "azur__lane" instead of "azur_lane". --- app/models/wiki_page.rb | 2 +- test/unit/wiki_page_test.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index a38f782d0..2f0fceb7d 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -150,7 +150,7 @@ class WikiPage < ApplicationRecord end def self.normalize_title(title) - title.to_s.downcase.delete_prefix("~").gsub(/[[:space:]]+/, "_").gsub(/__/, "_").gsub(/\A_|_\z/, "") + title.to_s.downcase.delete_prefix("~").gsub(/[[:space:]]+/, "_").squeeze("_").gsub(/\A_|_\z/, "") end def normalize_other_names diff --git a/test/unit/wiki_page_test.rb b/test/unit/wiki_page_test.rb index 0ed9ca5a3..6f0f557bf 100644 --- a/test/unit/wiki_page_test.rb +++ b/test/unit/wiki_page_test.rb @@ -98,7 +98,10 @@ class WikiPageTest < ActiveSupport::TestCase should normalize_attribute(:title).from("foo_").to("foo") should normalize_attribute(:title).from("FOO").to("foo") should normalize_attribute(:title).from("foo__bar").to("foo_bar") + should normalize_attribute(:title).from("foo___bar").to("foo_bar") + should normalize_attribute(:title).from("___foo___bar___").to("foo_bar") should normalize_attribute(:title).from("foo bar").to("foo_bar") + should normalize_attribute(:title).from(" Foo___ Bar ").to("foo_bar") should_not allow_value("").for(:title).on(:create) should_not allow_value("___").for(:title).on(:create)