Commit 17ea019f4e43b4fb394544f9d86ab3016f54d28e

Authored by Andrey Kumanyaev
1 parent c4536ae5

Add Project name validation

Showing 2 changed files with 7 additions and 1 deletions   Show diff stats
app/models/project.rb
@@ -64,7 +64,9 @@ class Project < ActiveRecord::Base @@ -64,7 +64,9 @@ class Project < ActiveRecord::Base
64 # Validations 64 # Validations
65 validates :owner, presence: true 65 validates :owner, presence: true
66 validates :description, length: { within: 0..2000 } 66 validates :description, length: { within: 0..2000 }
67 - validates :name, presence: true, length: { within: 0..255 } 67 + validates :name, presence: true, length: { within: 0..255 },
  68 + format: { with: Gitlab::Regex.project_name_regex,
  69 + message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
68 validates :path, presence: true, length: { within: 0..255 }, 70 validates :path, presence: true, length: { within: 0..255 },
69 format: { with: Gitlab::Regex.path_regex, 71 format: { with: Gitlab::Regex.path_regex,
70 message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" } 72 message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
lib/gitlab/regex.rb
@@ -6,6 +6,10 @@ module Gitlab @@ -6,6 +6,10 @@ module Gitlab
6 default_regex 6 default_regex
7 end 7 end
8 8
  9 + def project_name_regex
  10 + default_regex
  11 + end
  12 +
9 def path_regex 13 def path_regex
10 default_regex 14 default_regex
11 end 15 end