diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-02-24 09:38:44 -0600 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-02-24 09:55:01 -0600 |
commit | c72e71552209aae964e5aa931d435f7e1164e5d1 (patch) | |
tree | 2e7a17e1216e8286ba885f9d0517330b9148b879 | |
parent | a530e9da3580e05a171b3ba0a3f4408afc000b10 (diff) | |
download | gitlab-ce-c72e71552209aae964e5aa931d435f7e1164e5d1.tar.gz |
Raise error when no content is provided
-rw-r--r-- | app/services/files/create_service.rb | 4 | ||||
-rw-r--r-- | app/services/files/multi_service.rb | 22 | ||||
-rw-r--r-- | app/services/files/update_service.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/git/index.rb | 2 |
4 files changed, 23 insertions, 9 deletions
diff --git a/app/services/files/create_service.rb b/app/services/files/create_service.rb index 63be33409e2..ec45a60eda1 100644 --- a/app/services/files/create_service.rb +++ b/app/services/files/create_service.rb @@ -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 ' + diff --git a/app/services/files/multi_service.rb b/app/services/files/multi_service.rb index 2c89f6e7f92..93f77f29aff 100644 --- a/app/services/files/multi_service.rb +++ b/app/services/files/multi_service.rb @@ -27,7 +27,7 @@ module Files else raise_error("Unknown action type `#{action[:action]}`.") end - + unless action[:file_path].present? raise_error("You must specify a file_path.") end @@ -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 diff --git a/app/services/files/update_service.rb b/app/services/files/update_service.rb index a71fe61a4b6..462de06b6ff 100644 --- a/app/services/files/update_service.rb +++ b/app/services/files/update_service.rb @@ -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 diff --git a/lib/gitlab/git/index.rb b/lib/gitlab/git/index.rb index 546696e4bd1..af1744c9c46 100644 --- a/lib/gitlab/git/index.rb +++ b/lib/gitlab/git/index.rb @@ -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) |