From cda94538e6d6379d3f99eeafd20addc3e7eb5220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Mon, 20 May 2024 12:20:54 +0200 Subject: [PATCH] #1464 some optimizations --- lib/redmine_dmsf/webdav/base_resource.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/redmine_dmsf/webdav/base_resource.rb b/lib/redmine_dmsf/webdav/base_resource.rb index 7fe73dec..76916108 100644 --- a/lib/redmine_dmsf/webdav/base_resource.rb +++ b/lib/redmine_dmsf/webdav/base_resource.rb @@ -114,17 +114,13 @@ def html_display # Run method through proxy class - ensuring always compatible child is generated def child(name) - new_path = @path - new_path = "#{new_path}/" unless new_path[-1, 1] == '/' - new_path = "/#{new_path}" unless new_path[0, 1] == '/' + new_path = normalized_path ResourceProxy.new "#{new_path}#{name}", request, response, @options.merge(user: @user) end def child_project(project) project_display_name = ProjectResource.create_project_name(project) - new_path = @path - new_path = "#{new_path}/" unless new_path[-1, 1] == '/' - new_path = "/#{new_path}" unless new_path[0, 1] == '/' + new_path = normalized_path new_path += project_display_name ResourceProxy.new new_path, request, response, @options.merge(user: @user, project: true) end @@ -185,6 +181,13 @@ def get_project(scope, name, parent_project) protected + # Add slash at the beginning and the end if missing + def normalized_path + new_path = @path + new_path << '/' unless new_path.end_with?('/') + new_path.start_with?('/') ? new_path : new_path.insert(0, '/') + end + def uri_encode(uri) uri.gsub(/[()&\[\]]/, '(' => '%28', ')' => '%29', '&' => '%26', '[' => '%5B', ']' => '5D') end