Commit c72e7155 authored by Douwe Maan's avatar Douwe Maan

Raise error when no content is provided

parent a530e9da
......@@ -16,6 +16,10 @@ module Files
def validate
super
if @file_content.empty?
raise_error("You must provide content.")
end
if @file_path =~ Gitlab::Regex.directory_traversal_regex
raise_error(
'Your changes could not be committed, because the file name ' +
......
......@@ -100,6 +100,20 @@ module Files
if repository.blob_at_branch(params[:branch], action[:file_path])
raise_error("Your changes could not be committed because a file with the name `#{action[:file_path]}` already exists.")
end
if action[:content].empty?
raise_error("You must provide content.")
end
end
def validate_update(action)
if action[:content].empty?
raise_error("You must provide content.")
end
if file_has_changed?
raise FileChangedError.new("You are attempting to update a file `#{action[:file_path]}` that has changed since you started editing it.")
end
end
def validate_delete(action)
......@@ -122,11 +136,5 @@ module Files
params[:actions][index][:content] = blob.data
end
end
def validate_update(action)
if file_has_changed?
raise FileChangedError.new("You are attempting to update a file `#{action[:file_path]}` that has changed since you started editing it.")
end
end
end
end
......@@ -18,6 +18,10 @@ module Files
def validate
super
if @file_content.empty?
raise_error("You must provide content.")
end
if file_has_changed?
raise FileChangedError.new("You are attempting to update a file that has changed since you started editing it.")
end
......
......@@ -106,8 +106,6 @@ module Gitlab
def add_blob(options, mode: nil)
content = options[:content]
return unless content
content = Base64.decode64(content) if options[:encoding] == 'base64'
detect = CharlockHolmes::EncodingDetector.new.detect(content)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment