wiki pages: fix normalization of wiki page title.

Fix the wiki page title "azur___lane" being normalized to "azur__lane"
instead of "azur_lane".
This commit is contained in:
evazion
2021-01-09 18:42:33 -06:00
parent ff6e640fcb
commit 7fbac34962
2 changed files with 4 additions and 1 deletions

View File

@@ -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

View File

@@ -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)