diff --git a/app/site_files.rb b/app/site_files.rb index 2df30ac9..cf06c470 100644 --- a/app/site_files.rb +++ b/app/site_files.rb @@ -152,11 +152,12 @@ get '/site_files/:username.zip' do |username| send_file zipfile_path end -get '/site_files/download/:filename' do |filename| +get %r{\/site_files\/download\/(.+)} do require_login - content_type 'application/octet-stream' + not_found if params[:captures].nil? || params[:captures].length != 1 + filename = params[:captures].first attachment filename - current_site.get_file filename + send_file current_site.current_files_path(filename) end get %r{\/site_files\/text_editor\/(.+)} do @@ -174,16 +175,18 @@ get %r{\/site_files\/text_editor\/(.+)} do nil end - begin - @file_data = current_site.get_file @filename - rescue Errno::ENOENT - flash[:error] = 'We could not find the requested file.' - redirect '/dashboard' - rescue Errno::EISDIR + file_path = current_site.current_files_path @filename + + if File.directory? file_path flash[:error] = 'Cannot edit a directory.' redirect '/dashboard' end + if !File.exist?(file_path) + flash[:error] = 'We could not find the requested file.' + redirect '/dashboard' + end + @title = "Editing #{@filename}" erb :'site_files/text_editor' diff --git a/views/site_files/text_editor.erb b/views/site_files/text_editor.erb index 0a384336..fcecb0eb 100644 --- a/views/site_files/text_editor.erb +++ b/views/site_files/text_editor.erb @@ -120,7 +120,7 @@ if(unsavedChanges == false) return $.ajax({ - url: '/site_files/save/<%= @filename %>?csrf_token=<%= Rack::Utils.escape csrf_token %>', + url: "/site_files/save/<%= Addressable::URI.encode @filename %>?csrf_token=<%= Rack::Utils.escape csrf_token %>", data: editor.getValue(), processData: false, contentType: false,