about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authormasarakki <masaki182@gmail.com>2017-07-14 18:02:49 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-07-14 11:02:49 +0200
commita49be27145a858a51e1b9104b0ebc5f63a03b81b (patch)
tree8337aa515bdf3aea8124e6404eb4fb1177ba5c2c /app
parent27b2355738482a2e470281136bfe902ad6c78db8 (diff)
add validation to tag name (#4194)
Diffstat (limited to 'app')
-rw-r--r--app/models/tag.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/app/models/tag.rb b/app/models/tag.rb
index a14e2cc98..0fa08e157 100644
--- a/app/models/tag.rb
+++ b/app/models/tag.rb
@@ -12,9 +12,10 @@
 class Tag < ApplicationRecord
   has_and_belongs_to_many :statuses
 
-  HASHTAG_RE = /(?:^|[^\/\)\w])#([[:word:]_]*[[:alpha:]_][[:word:]_]*)/i
+  HASHTAG_NAME_RE = '[[:word:]_]*[[:alpha:]_][[:word:]_]*'
+  HASHTAG_RE = /(?:^|[^\/\)\w])#(#{HASHTAG_NAME_RE})/i
 
-  validates :name, presence: true, uniqueness: true
+  validates :name, presence: true, uniqueness: true, format: { with: /\A#{HASHTAG_NAME_RE}\z/i }
 
   def to_param
     name