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.
This commit is contained in:
@@ -17,6 +17,7 @@ class String
|
|||||||
alias :upstream_to_url :to_url
|
alias :upstream_to_url :to_url
|
||||||
# _Header => header which causes errors
|
# _Header => header which causes errors
|
||||||
def to_url
|
def to_url
|
||||||
|
return nil if self.nil?
|
||||||
return self if ['_Header', '_Footer', '_Sidebar'].include? self
|
return self if ['_Header', '_Footer', '_Sidebar'].include? self
|
||||||
upstream_to_url
|
upstream_to_url
|
||||||
end
|
end
|
||||||
@@ -124,7 +125,8 @@ module Precious
|
|||||||
wiki_options = settings.wiki_options.merge({ :page_file_dir => path })
|
wiki_options = settings.wiki_options.merge({ :page_file_dir => path })
|
||||||
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
|
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
|
||||||
page = wiki.page(CGI.unescape(params[:page]))
|
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)
|
committer = Gollum::Committer.new(wiki, commit_message)
|
||||||
commit = {:committer => committer}
|
commit = {:committer => committer}
|
||||||
|
|
||||||
@@ -134,14 +136,14 @@ module Precious
|
|||||||
update_wiki_page(wiki, page.sidebar, params[:sidebar], commit) if params[:sidebar]
|
update_wiki_page(wiki, page.sidebar, params[:sidebar], commit) if params[:sidebar]
|
||||||
committer.commit
|
committer.commit
|
||||||
|
|
||||||
page = wiki.page(params[:rename]) if params[:rename]
|
page = wiki.page(rename) if rename
|
||||||
|
|
||||||
redirect "/#{page.escaped_url_path}"
|
redirect "/#{page.escaped_url_path}"
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/delete/*' do
|
get '/delete/*' do
|
||||||
@path = extract_path(params[:splat].first)
|
@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_options = settings.wiki_options.merge({ :page_file_dir => @path })
|
||||||
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
|
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
|
||||||
@page = wiki.page(@name)
|
@page = wiki.page(@name)
|
||||||
|
|||||||
+1
-1
@@ -88,7 +88,7 @@ context "Frontend" do
|
|||||||
:rename => "C", :page => 'B',
|
:rename => "C", :page => 'B',
|
||||||
:format => page_1.format, :message => 'def'
|
:format => page_1.format, :message => 'def'
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert_equal "/C", last_request.fullpath
|
assert_equal '/c', last_request.fullpath
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
|
|
||||||
@wiki.clear_cache
|
@wiki.clear_cache
|
||||||
|
|||||||
Reference in New Issue
Block a user