fixes #2526: Don't allow special characters ('*', etc...) in artist names
This commit is contained in:
@@ -5,6 +5,7 @@ class Artist < ActiveRecord::Base
|
||||
after_save :save_url_string
|
||||
after_save :categorize_tag
|
||||
validates_uniqueness_of :name
|
||||
validate :name_is_valid
|
||||
belongs_to :creator, :class_name => "User"
|
||||
has_many :members, :class_name => "Artist", :foreign_key => "group_name", :primary_key => "name"
|
||||
has_many :urls, :dependent => :destroy, :class_name => "ArtistUrl"
|
||||
@@ -85,6 +86,18 @@ class Artist < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def name_is_valid
|
||||
if name =~ /^[-~]/
|
||||
errors[:name] << "cannot begin with - or ~"
|
||||
false
|
||||
elsif name =~ /\*/
|
||||
errors[:name] << "cannot contain *"
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def normalize_name
|
||||
self.name = Artist.normalize_name(name)
|
||||
end
|
||||
|
||||
@@ -31,6 +31,12 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
should "should have a valid name" do
|
||||
@artist = Artist.new(:name => "-blah")
|
||||
@artist.save
|
||||
assert_equal(["Name cannot begin with - or ~"], @artist.errors.full_messages)
|
||||
end
|
||||
|
||||
context "with a matching tag alias" do
|
||||
setup do
|
||||
@tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
|
||||
Reference in New Issue
Block a user