Extract username regex

This commit is contained in:
Carl Chenet 2017-05-20 15:29:35 +02:00
parent 80c2ac5c8f
commit 19ac5369c5
2 changed files with 3 additions and 2 deletions

View File

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

View File

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