Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add parser error if invalid metadata json

Oliver Güntherf60b86da2d1d
diff --git a/app/contracts/attachments/prepare_upload_contract.rb b/app/contracts/attachments/prepare_upload_contract.rb
index 456c2eb0ab0..91f6a717dee 100644
--- a/app/contracts/attachments/prepare_upload_contract.rb
+++ b/app/contracts/attachments/prepare_upload_contract.rb
@@ -31,8 +31,6 @@
module Attachments
class PrepareUploadContract < CreateContract
validate :validate_direct_uploads_active
- # prepared uploads require a filesize to be present
- validates :filesize, presence: true
private
diff --git a/lib/api/v3/attachments/attachments_by_container_api.rb b/lib/api/v3/attachments/attachments_by_container_api.rb
index c9b76afede7..6616b8e0b0b 100644
--- a/lib/api/v3/attachments/attachments_by_container_api.rb
+++ b/lib/api/v3/attachments/attachments_by_container_api.rb
@@ -58,6 +58,8 @@ module API
request.params.tap do |params|
params[:metadata] = JSON.parse(params[:metadata]) if params.key?(:metadata)
end
+ rescue JSON::ParserError
+ raise ::API::Errors::InvalidRequestBody.new(I18n.t('api_v3.errors.multipart_body_error'))
end
end
diff --git a/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb b/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb
index 6926c64c92e..0a88b8199fc 100644
--- a/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb
+++ b/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb
@@ -289,6 +289,7 @@ shared_examples 'an APIv3 attachment resource', type: :request, content_type: :j
context 'file is too large' do
let(:file) { mock_uploaded_file(content: 'a' * 2.kilobytes) }
+
let(:expanded_localization) do
I18n.t('activerecord.errors.messages.file_too_large', count: max_file_size.kilobytes)
end