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

remove trailing slashes of storage host upon creation

Christophe Bliardb0641a6b3014
diff --git a/modules/storages/app/services/storages/storages/set_attributes_service.rb b/modules/storages/app/services/storages/storages/set_attributes_service.rb
index 39dd42669a0..fedcbda8344 100644
--- a/modules/storages/app/services/storages/storages/set_attributes_service.rb
+++ b/modules/storages/app/services/storages/storages/set_attributes_service.rb
@@ -29,6 +29,8 @@
# See also: create_service.rb for comments
module Storages::Storages
class SetAttributesService < ::BaseServices::SetAttributes
+ after_call :remove_host_trailing_slashes
+
def set_default_attributes(_params)
storage.creator ||= user
storage.name ||= I18n.t('storages.provider_types.nextcloud')
@@ -37,6 +39,10 @@ module Storages::Storages
private
+ def remove_host_trailing_slashes
+ storage.host = storage.host&.gsub(/\/+$/, '')
+ end
+
def storage
model
end
diff --git a/modules/storages/spec/services/storages/storages/set_attributes_service_spec.rb b/modules/storages/spec/services/storages/storages/set_attributes_service_spec.rb
index 816773f8d35..a31da994b89 100644
--- a/modules/storages/spec/services/storages/storages/set_attributes_service_spec.rb
+++ b/modules/storages/spec/services/storages/storages/set_attributes_service_spec.rb
@@ -93,6 +93,16 @@ describe ::Storages::Storages::SetAttributesService, type: :model do
it 'sets name to Nextcloud by default' do
expect(subject.result.name).to eq I18n.t('storages.provider_types.nextcloud')
end
+
+ context 'when setting host' do
+ before do
+ params[:host] = "https://some.host.com//"
+ end
+
+ it 'removes trailing slashes from host' do
+ expect(subject.result.host).to eq("https://some.host.com")
+ end
+ end
end
context 'with existing record' do