summaryrefslogtreecommitdiff
path: root/app/models/snippet.rb
diff options
context:
space:
mode:
authorVinnie Okada <vokada@mrvinn.com>2015-03-17 20:53:09 -0600
committerVinnie Okada <vokada@mrvinn.com>2015-03-17 20:53:09 -0600
commitfeeffc442618d92040cd1cc38158b689a09988fd (patch)
treeb19c0ac2ddae23d830bbc69b99d920eec1f81363 /app/models/snippet.rb
parent1a9c2ddc55cf563ea42d67811a19b2693d7a44e9 (diff)
parent5bbc70da9cb439342bdbe022988e4e734d891f44 (diff)
downloadgitlab-ce-feeffc442618d92040cd1cc38158b689a09988fd.tar.gz
Merge branch 'master' into markdown-tags
Use the latest HTML pipeline gem
Diffstat (limited to 'app/models/snippet.rb')
-rw-r--r--app/models/snippet.rb17
1 files changed, 15 insertions, 2 deletions
diff --git a/app/models/snippet.rb b/app/models/snippet.rb
index a47fbca3260..3fb2ec1d66c 100644
--- a/app/models/snippet.rb
+++ b/app/models/snippet.rb
@@ -16,6 +16,7 @@
#
class Snippet < ActiveRecord::Base
+ include Sortable
include Linguist::BlobHelper
include Gitlab::VisibilityLevel
@@ -29,7 +30,11 @@ class Snippet < ActiveRecord::Base
validates :author, presence: true
validates :title, presence: true, length: { within: 0..255 }
- validates :file_name, presence: true, length: { within: 0..255 }
+ validates :file_name,
+ presence: true,
+ length: { within: 0..255 },
+ format: { with: Gitlab::Regex.path_regex,
+ message: Gitlab::Regex.path_regex_message }
validates :content, presence: true
validates :visibility_level, inclusion: { in: Gitlab::VisibilityLevel.values }
@@ -54,6 +59,10 @@ class Snippet < ActiveRecord::Base
content
end
+ def hook_attrs
+ attributes
+ end
+
def size
0
end
@@ -62,6 +71,10 @@ class Snippet < ActiveRecord::Base
file_name
end
+ def sanitized_file_name
+ file_name.gsub(/[^a-zA-Z0-9_\-\.]+/, '')
+ end
+
def mode
nil
end
@@ -72,7 +85,7 @@ class Snippet < ActiveRecord::Base
def visibility_level_field
visibility_level
- end
+ end
class << self
def search(query)