Extract username regex
This commit is contained in:
parent
80c2ac5c8f
commit
19ac5369c5
|
@ -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|
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue