From 3e5054f3571ce897858aaf04d83684f4e672030e Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Sun, 22 Jul 2012 13:37:09 -0600 Subject: [PATCH] Call to_url on rename to prevent invalid renames. Remove to_url on delete so invalid names can be deleted. Handle nil in to_url. Update tests. --- lib/gollum/frontend/app.rb | 8 +++++--- test/test_app.rb | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index 7dc4bc94..e20e4d48 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -17,6 +17,7 @@ class String alias :upstream_to_url :to_url # _Header => header which causes errors def to_url + return nil if self.nil? return self if ['_Header', '_Footer', '_Sidebar'].include? self upstream_to_url end @@ -124,7 +125,8 @@ module Precious wiki_options = settings.wiki_options.merge({ :page_file_dir => path }) wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options) page = wiki.page(CGI.unescape(params[:page])) - name = params[:rename] || page.name + rename = params[:rename].to_url if params[:rename] + name = rename || page.name committer = Gollum::Committer.new(wiki, commit_message) commit = {:committer => committer} @@ -134,14 +136,14 @@ module Precious update_wiki_page(wiki, page.sidebar, params[:sidebar], commit) if params[:sidebar] committer.commit - page = wiki.page(params[:rename]) if params[:rename] + page = wiki.page(rename) if rename redirect "/#{page.escaped_url_path}" end get '/delete/*' do @path = extract_path(params[:splat].first) - @name = extract_name(params[:splat].first).to_url + @name = extract_name(params[:splat].first) wiki_options = settings.wiki_options.merge({ :page_file_dir => @path }) wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options) @page = wiki.page(@name) diff --git a/test/test_app.rb b/test/test_app.rb index 9f5a4dbb..d76eab1e 100644 --- a/test/test_app.rb +++ b/test/test_app.rb @@ -88,7 +88,7 @@ context "Frontend" do :rename => "C", :page => 'B', :format => page_1.format, :message => 'def' follow_redirect! - assert_equal "/C", last_request.fullpath + assert_equal '/c', last_request.fullpath assert last_response.ok? @wiki.clear_cache