Page create with a relative path forces an absolute path.
This commit is contained in:
@@ -222,6 +222,7 @@ module Precious
|
|||||||
# not /docs/Home because write_page will append /docs
|
# not /docs/Home because write_page will append /docs
|
||||||
@path = @path.sub(page_dir, '/') if @path.start_with? page_dir
|
@path = @path.sub(page_dir, '/') if @path.start_with? page_dir
|
||||||
end
|
end
|
||||||
|
@path = clean_path(@path)
|
||||||
|
|
||||||
page = wikip.page
|
page = wikip.page
|
||||||
if page
|
if page
|
||||||
|
|||||||
@@ -25,6 +25,13 @@ module Precious
|
|||||||
[nil,''].include?(param) ? nil : CGI.unescape(param)
|
[nil,''].include?(param) ? nil : CGI.unescape(param)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Ensure path begins with a single leading slash
|
||||||
|
def clean_path(path)
|
||||||
|
if path
|
||||||
|
(path[0] != '/' ? path.insert(0, '/') : path).gsub('//','/')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Remove all slashes from the start of string.
|
# Remove all slashes from the start of string.
|
||||||
# Remove all double slashes
|
# Remove all double slashes
|
||||||
def clean_url url
|
def clean_url url
|
||||||
|
|||||||
+30
-11
@@ -5,14 +5,14 @@ context "Frontend" do
|
|||||||
include Rack::Test::Methods
|
include Rack::Test::Methods
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
@path = cloned_testpath("examples/revert.git")
|
@wikipath = cloned_testpath("examples/revert.git")
|
||||||
@wiki = Gollum::Wiki.new(@path)
|
@wiki = Gollum::Wiki.new(@wikipath)
|
||||||
Precious::App.set(:gollum_path, @path)
|
Precious::App.set(:gollum_path, @wikipath)
|
||||||
Precious::App.set(:wiki_options, {})
|
Precious::App.set(:wiki_options, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
FileUtils.rm_rf(@path)
|
FileUtils.rm_rf(@wikipath)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "urls transform unicode" do
|
test "urls transform unicode" do
|
||||||
@@ -300,6 +300,25 @@ context "Frontend" do
|
|||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "create sets the correct path for a relative path subdirectory" do
|
||||||
|
dir = "foodir"
|
||||||
|
name = "#{dir}/bar"
|
||||||
|
get "/create/#{name}"
|
||||||
|
assert_match(/\/#{dir}/, last_response.body)
|
||||||
|
assert_not_match(/(?<!\/)#{dir}/, last_response.body)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "create sets the correct path for a relative path subdirectory with the page file directory set" do
|
||||||
|
Precious::App.set(:wiki_options, {:page_file_dir => "foo"})
|
||||||
|
dir = "bardir"
|
||||||
|
name = "#{dir}/baz"
|
||||||
|
get "/create/foo/#{name}"
|
||||||
|
assert_match(/\/#{dir}/, last_response.body)
|
||||||
|
assert_not_match(/(?<!\/)#{dir}/, last_response.body)
|
||||||
|
# reset page_file_dir
|
||||||
|
Precious::App.set(:wiki_options, {:page_file_dir => nil})
|
||||||
|
end
|
||||||
|
|
||||||
test "edit returns nil for non-existant page" do
|
test "edit returns nil for non-existant page" do
|
||||||
# post '/edit' fails. post '/edit/' works.
|
# post '/edit' fails. post '/edit/' works.
|
||||||
page = 'not-real-page'
|
page = 'not-real-page'
|
||||||
@@ -372,9 +391,9 @@ context "Frontend" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "previews content on the first page of an empty wiki" do
|
test "previews content on the first page of an empty wiki" do
|
||||||
@path = cloned_testpath("examples/empty.git")
|
@wikipath = cloned_testpath("examples/empty.git")
|
||||||
@wiki = Gollum::Wiki.new(@path)
|
@wiki = Gollum::Wiki.new(@wikipath)
|
||||||
Precious::App.set(:gollum_path, @path)
|
Precious::App.set(:gollum_path, @wikipath)
|
||||||
Precious::App.set(:wiki_options, {})
|
Precious::App.set(:wiki_options, {})
|
||||||
|
|
||||||
post "/preview", :content => 'abc', :format => 'markdown'
|
post "/preview", :content => 'abc', :format => 'markdown'
|
||||||
@@ -494,14 +513,14 @@ context "Frontend with lotr" do
|
|||||||
include Rack::Test::Methods
|
include Rack::Test::Methods
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
@path = cloned_testpath("examples/lotr.git")
|
@wikipath = cloned_testpath("examples/lotr.git")
|
||||||
@wiki = Gollum::Wiki.new(@path)
|
@wiki = Gollum::Wiki.new(@wikipath)
|
||||||
Precious::App.set(:gollum_path, @path)
|
Precious::App.set(:gollum_path, @wikipath)
|
||||||
Precious::App.set(:wiki_options, {})
|
Precious::App.set(:wiki_options, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
FileUtils.rm_rf(@path)
|
FileUtils.rm_rf(@wikipath)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Here's the dir structure of lotr.git
|
# Here's the dir structure of lotr.git
|
||||||
|
|||||||
@@ -9,5 +9,17 @@ context "Precious::Helpers" do
|
|||||||
assert_equal 'Mordor', extract_path('Mordor/Sauron')
|
assert_equal 'Mordor', extract_path('Mordor/Sauron')
|
||||||
assert_equal 'Mordor/Sauron', extract_path('Mordor/Sauron/Evil')
|
assert_equal 'Mordor/Sauron', extract_path('Mordor/Sauron/Evil')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "clean path without leading slash" do
|
||||||
|
assert_equal '/Mordor', clean_path('Mordor')
|
||||||
|
end
|
||||||
|
|
||||||
|
test "clean path with leading slash" do
|
||||||
|
assert_equal '/Mordor', clean_path('/Mordor')
|
||||||
|
end
|
||||||
|
|
||||||
|
test "clean path with double leading slash" do
|
||||||
|
assert_equal '/Mordor', clean_path('//Mordor')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user