Merge pull request #659 from cpence/master
Fix symlink base path, don't allow in bare repos
This commit is contained in:
+2
-2
@@ -44,8 +44,8 @@ module Gollum
|
|||||||
def raw_data
|
def raw_data
|
||||||
return nil unless @blob
|
return nil unless @blob
|
||||||
|
|
||||||
if @blob.is_symlink
|
if !@wiki.repo.bare && @blob.is_symlink
|
||||||
new_path = @blob.symlink_target(self.path)
|
new_path = @blob.symlink_target(::File.join(@wiki.repo.path, '..', self.path))
|
||||||
return IO.read(new_path) if new_path
|
return IO.read(new_path) if new_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -182,8 +182,8 @@ module Gollum
|
|||||||
def raw_data
|
def raw_data
|
||||||
return nil unless @blob
|
return nil unless @blob
|
||||||
|
|
||||||
if @blob.is_symlink
|
if !@wiki.repo.bare && @blob.is_symlink
|
||||||
new_path = @blob.symlink_target(::File.join(@wiki.repo.path, self.path))
|
new_path = @blob.symlink_target(::File.join(@wiki.repo.path, '..', self.path))
|
||||||
return IO.read(new_path) if new_path
|
return IO.read(new_path) if new_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -485,11 +485,13 @@ context "Frontend with lotr" do
|
|||||||
# .
|
# .
|
||||||
# ├── Bilbo-Baggins.md
|
# ├── Bilbo-Baggins.md
|
||||||
# ├── Data.csv
|
# ├── Data.csv
|
||||||
|
# |-- Data-Two.csv -> Data.csv
|
||||||
# ├── Gondor
|
# ├── Gondor
|
||||||
# │ ├── Boromir.md
|
# │ ├── Boromir.md
|
||||||
# │ ├── _Footer.md
|
# │ ├── _Footer.md
|
||||||
# │ ├── _Header.md
|
# │ ├── _Header.md
|
||||||
# │ └── _Sidebar.md
|
# │ └── _Sidebar.md
|
||||||
|
# |-- Hobbit.md -> Bilbo-Baggins.md
|
||||||
# ├── Home.textile
|
# ├── Home.textile
|
||||||
# ├── Mordor
|
# ├── Mordor
|
||||||
# │ ├── Eye-Of-Sauron.md
|
# │ ├── Eye-Of-Sauron.md
|
||||||
@@ -528,6 +530,11 @@ context "Frontend with lotr" do
|
|||||||
assert body.include?("Eye Of Sauron"), "/pages/Mordor/ should include the page 'Eye Of Sauron'"
|
assert body.include?("Eye Of Sauron"), "/pages/Mordor/ should include the page 'Eye Of Sauron'"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "symbolic link pages" do
|
||||||
|
get "/Hobbit"
|
||||||
|
assert_match /Bilbo Baggins/, last_response.body
|
||||||
|
end
|
||||||
|
|
||||||
# base path requires 'map' in a config.ru to work correctly.
|
# base path requires 'map' in a config.ru to work correctly.
|
||||||
test "create pages within sub-directories using base path" do
|
test "create pages within sub-directories using base path" do
|
||||||
Precious::App.set(:wiki_options, { :base_path => 'wiki' })
|
Precious::App.set(:wiki_options, { :base_path => 'wiki' })
|
||||||
|
|||||||
+17
-13
@@ -21,21 +21,25 @@ context "File" do
|
|||||||
assert_equal commit.author.name, file.version.author.name
|
assert_equal commit.author.name, file.version.author.name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "accessing tree" do
|
||||||
|
assert_nil @wiki.file("Mordor")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "File with checkout" do
|
||||||
|
setup do
|
||||||
|
@path = cloned_testpath("examples/lotr.git")
|
||||||
|
@wiki = Gollum::Wiki.new(@path)
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
FileUtils.rm_rf(@path)
|
||||||
|
end
|
||||||
|
|
||||||
test "symbolic link" do
|
test "symbolic link" do
|
||||||
commit = @wiki.repo.commits.first
|
commit = @wiki.repo.commits.first
|
||||||
file = @wiki.file("Data-Two.csv")
|
file = @wiki.file("Data-Two.csv")
|
||||||
|
|
||||||
# Since we don't have a checkout here (bare repos in testing), these
|
assert_match /^FirstName,LastName\n/, file.raw_data
|
||||||
# symbolic links won't resolve. Stub IO.read to simulate the behavior
|
|
||||||
# and make sure all is working well.
|
|
||||||
path_to_link = File.expand_path(File.join('..', '..', 'Data.csv'), __FILE__)
|
|
||||||
File.expects(:file?).with(path_to_link).returns(true)
|
|
||||||
IO.expects(:read).with(path_to_link).returns('symlink test')
|
|
||||||
|
|
||||||
assert_equal file.raw_data, 'symlink test'
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
test "accessing tree" do
|
|
||||||
assert_nil @wiki.file("Mordor")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|||||||
+20
-17
@@ -34,23 +34,6 @@ context "Page" do
|
|||||||
assert_nil @wiki.page('Bilbo_Baggins')
|
assert_nil @wiki.page('Bilbo_Baggins')
|
||||||
end
|
end
|
||||||
|
|
||||||
test "get existing page with symbolic link" do
|
|
||||||
page = @wiki.page("Hobbit")
|
|
||||||
assert_equal Gollum::Page, page.class
|
|
||||||
assert_equal 'Hobbit.md', page.path
|
|
||||||
assert_equal :markdown, page.format
|
|
||||||
|
|
||||||
# Since we don't have a checkout here (bare repos in testing), these
|
|
||||||
# symbolic links won't resolve. Stub IO.read to simulate the behavior
|
|
||||||
# and make sure all is working well.
|
|
||||||
path_to_link = File.expand_path(File.join('..', 'examples', 'lotr.git', 'Bilbo-Baggins.md'), __FILE__)
|
|
||||||
File.expects(:file?).with(path_to_link).returns(true).at_least_once
|
|
||||||
IO.expects(:read).with(path_to_link).returns("# Bilbo Baggins\n\nBilbo Baggins").at_least_once
|
|
||||||
|
|
||||||
assert page.raw_data =~ /^# Bilbo Baggins\n\nBilbo Baggins/
|
|
||||||
assert page.formatted_data =~ %r{<h1>Bilbo Baggins<a class="anchor" id="Bilbo-Baggins" href="#Bilbo-Baggins"></a></h1>\n\n<p>Bilbo Baggins}
|
|
||||||
end
|
|
||||||
|
|
||||||
test "get existing page where filename contains whitespace, with hypen" do
|
test "get existing page where filename contains whitespace, with hypen" do
|
||||||
assert_equal @wiki.page('Samwise Gamgee').path, @wiki.page('Samwise-Gamgee').path
|
assert_equal @wiki.page('Samwise Gamgee').path, @wiki.page('Samwise-Gamgee').path
|
||||||
end
|
end
|
||||||
@@ -214,6 +197,26 @@ context "Page" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with a checkout" do
|
||||||
|
setup do
|
||||||
|
@path = cloned_testpath("examples/lotr.git")
|
||||||
|
@wiki = Gollum::Wiki.new(@path)
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
FileUtils.rm_rf(@path)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "get existing page with symbolic link" do
|
||||||
|
page = @wiki.page("Hobbit")
|
||||||
|
assert_equal Gollum::Page, page.class
|
||||||
|
assert page.raw_data =~ /^# Bilbo Baggins\n\nBilbo Baggins/
|
||||||
|
assert page.formatted_data =~ %r{<h1>Bilbo Baggins<a class="anchor" id="Bilbo-Baggins" href="#Bilbo-Baggins"></a></h1>\n\n<p>Bilbo Baggins}
|
||||||
|
assert_equal 'Hobbit.md', page.path
|
||||||
|
assert_equal :markdown, page.format
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "within a sub-directory" do
|
context "within a sub-directory" do
|
||||||
setup do
|
setup do
|
||||||
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"), { :page_file_dir => 'Rivendell' })
|
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"), { :page_file_dir => 'Rivendell' })
|
||||||
|
|||||||
Reference in New Issue
Block a user