diff --git a/app/models/user.rb b/app/models/user.rb index a5b4638..cf12ce0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -55,8 +55,9 @@ class User < ActiveRecord::Base validates :password, :presence => true, :on => :create + VALID_USERNAME = /[A-Za-z0-9][A-Za-z0-9_-]{0,24}/ validates :username, - :format => { :with => /\A[A-Za-z0-9][A-Za-z0-9_-]{0,24}\Z/ }, + :format => { :with => /\A#{VALID_USERNAME}\Z/ }, :uniqueness => { :case_sensitive => false } validates_each :username do |record,attr,value| diff --git a/extras/markdowner.rb b/extras/markdowner.rb index 2194dfb..7af5fe3 100644 --- a/extras/markdowner.rb +++ b/extras/markdowner.rb @@ -44,7 +44,7 @@ class Markdowner def self.postprocess_text_node(node) while node - return unless node.string_content =~ /\B(@[\w\-]+)/ + return unless node.string_content =~ /\B(@#{User::VALID_USERNAME})/ before, user, after = $`, $1, $' node.string_content = before