Skip to content
Snippets Groups Projects
Commit fe706c18 authored by bootstraponline's avatar bootstraponline
Browse files

Merge pull request #659 from cpence/master

Fix symlink base path, don't allow in bare repos
parents e21ec540 90bbb8e3
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -44,8 +44,8 @@ module Gollum
def raw_data
return nil unless @blob
 
if @blob.is_symlink
new_path = @blob.symlink_target(self.path)
if !@wiki.repo.bare && @blob.is_symlink
new_path = @blob.symlink_target(::File.join(@wiki.repo.path, '..', self.path))
return IO.read(new_path) if new_path
end
 
Loading
Loading
Loading
Loading
@@ -182,8 +182,8 @@ module Gollum
def raw_data
return nil unless @blob
 
if @blob.is_symlink
new_path = @blob.symlink_target(::File.join(@wiki.repo.path, self.path))
if !@wiki.repo.bare && @blob.is_symlink
new_path = @blob.symlink_target(::File.join(@wiki.repo.path, '..', self.path))
return IO.read(new_path) if new_path
end
 
Loading
Loading
Loading
Loading
@@ -485,11 +485,13 @@ context "Frontend with lotr" do
# .
# ├── Bilbo-Baggins.md
# ├── Data.csv
# |-- Data-Two.csv -> Data.csv
# ├── Gondor
# │ ├── Boromir.md
# │ ├── _Footer.md
# │ ├── _Header.md
# │ └── _Sidebar.md
# |-- Hobbit.md -> Bilbo-Baggins.md
# ├── Home.textile
# ├── Mordor
# │ ├── Eye-Of-Sauron.md
Loading
Loading
@@ -528,6 +530,11 @@ context "Frontend with lotr" do
assert body.include?("Eye Of Sauron"), "/pages/Mordor/ should include the page 'Eye Of Sauron'"
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.
test "create pages within sub-directories using base path" do
Precious::App.set(:wiki_options, { :base_path => 'wiki' })
Loading
Loading
Loading
Loading
@@ -21,21 +21,25 @@ context "File" do
assert_equal commit.author.name, file.version.author.name
end
 
test "symbolic link" do
commit = @wiki.repo.commits.first
file = @wiki.file("Data-Two.csv")
test "accessing tree" do
assert_nil @wiki.file("Mordor")
end
end
 
# 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('..', '..', 'Data.csv'), __FILE__)
File.expects(:file?).with(path_to_link).returns(true)
IO.expects(:read).with(path_to_link).returns('symlink test')
context "File with checkout" do
setup do
@path = cloned_testpath("examples/lotr.git")
@wiki = Gollum::Wiki.new(@path)
end
 
assert_equal file.raw_data, 'symlink test'
teardown do
FileUtils.rm_rf(@path)
end
 
test "accessing tree" do
assert_nil @wiki.file("Mordor")
test "symbolic link" do
commit = @wiki.repo.commits.first
file = @wiki.file("Data-Two.csv")
assert_match /^FirstName,LastName\n/, file.raw_data
end
end
\ No newline at end of file
end
Loading
Loading
@@ -34,23 +34,6 @@ context "Page" do
assert_nil @wiki.page('Bilbo_Baggins')
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
assert_equal @wiki.page('Samwise Gamgee').path, @wiki.page('Samwise-Gamgee').path
end
Loading
Loading
@@ -214,6 +197,26 @@ context "Page" do
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
setup do
@wiki = Gollum::Wiki.new(testpath("examples/lotr.git"), { :page_file_dir => 'Rivendell' })
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment