From 06778925e020a588615ebe7aefc4eaf41240529c Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Wed, 11 Nov 2015 13:50:24 -0800 Subject: [PATCH] Fixes for webdav directories --- app/site.rb | 1 - config.ru | 5 +++++ models/site.rb | 4 +++- tests/site_tests.rb | 13 +++++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/site.rb b/app/site.rb index d716ec56..3e10291a 100644 --- a/app/site.rb +++ b/app/site.rb @@ -161,7 +161,6 @@ post '/site/create_directory' do require_login path = "#{params[:dir] || ''}/#{params[:name]}" - result = current_site.create_directory path if result != true diff --git a/config.ru b/config.ru index 60e16ca4..e0ef012d 100644 --- a/config.ru +++ b/config.ru @@ -42,6 +42,11 @@ map '/webdav' do end end + if env['REQUEST_METHOD'] == 'MKCOL' + site.create_directory env['PATH_INFO'] + return [201, {}, ['']] + end + if env['REQUEST_METHOD'] == 'MOVE' tmpfile = Tempfile.new 'moved_file' tmpfile.close diff --git a/models/site.rb b/models/site.rb index f8cc90d8..e75bc64f 100644 --- a/models/site.rb +++ b/models/site.rb @@ -671,7 +671,7 @@ class Site < Sequel::Model return 'Directory (or file) already exists.' end - path_dirs = path.to_s.split '/' + path_dirs = path.to_s.split('/').select {|p| ![nil, '.', ''].include?(p) } path_site_file = '' @@ -682,6 +682,8 @@ class Site < Sequel::Model path_site_file += '/' + path_dirs.shift end + raise ArgumentError, 'directory name cannot be empty' if path_site_file == '' + site_file = SiteFile.where(site_id: self.id, path: path_site_file).first if site_file.nil? diff --git a/tests/site_tests.rb b/tests/site_tests.rb index 9fbb8ef1..297ba269 100644 --- a/tests/site_tests.rb +++ b/tests/site_tests.rb @@ -5,6 +5,19 @@ def app end describe Site do + describe 'directory create' do + it 'handles wacky pathnames' do + ['/derp', '/derp/'].each do |path| + site = Fabricate :site + site_file_count = site.site_files_dataset.count + site.create_directory path + site.site_files.select {|s| s.path == '' || s.path == '.'}.length.must_equal 0 + site.site_files.select {|s| s.path == path.gsub('/', '')}.first.wont_be_nil + site.site_files_dataset.count.must_equal site_file_count+1 + end + end + end + describe 'custom_max_space' do it 'should use the custom max space if it is more' do site = Fabricate :site