Skip to content

Commit

Permalink
Merge pull request #452 from repotag/fix_gollum1978
Browse files Browse the repository at this point in the history
Fix absolute path includes from a subdir
  • Loading branch information
dometto authored Aug 1, 2023
2 parents 15aae49 + 98fd9c4 commit dbca58f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/gollum-lib/filter/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ def parse_tag_parts(tag)
def process_include_tag(tag)
len = INCLUDE_TAG.length
return html_error('Cannot process include directive: no page name given') if tag.length <= len
page_name = tag[len..-1]
resolved_page_name = ::File.join(@markup.dir, page_name)
page_path = Pathname.new(tag[len..-1])
resolved_page = page_path.relative? ? (Pathname.new(@markup.dir) + page_path) : page_path
resolved_page_name = resolved_page.cleanpath.to_s
if @markup.include_levels > 0
page = find_page_or_file_from_path(resolved_page_name)
if page
Expand Down
7 changes: 7 additions & 0 deletions test/test_markup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,13 @@
assert_html_equal("<p>hello<br /></p><p>&lt;java</p><p>script&gt;alert(99);</p>", page1.formatted_data)
end

test "include directive with absolute path from subdir" do
@wiki.write_page("/subdir/page1", :textile, "hello\n[[include:/a/very/long/path/to/page2]]\n", commit_details)
@wiki.write_page("/a/very/long/path/to/page2", :textile, "success", commit_details)
page1 = @wiki.page("/subdir/page1")
assert_html_equal("<p>hello<br/></p><p>success</p>", page1.formatted_data)
end

test "include directive with very long absolute path and relative include" do
@wiki.write_page("page1", :textile, "hello\n[[include:/a/very/long/path/to/page2]]\n", commit_details)
@wiki.write_page("/a/very/long/path/to/page2", :textile, "goodbye\n[[include:object]]", commit_details)
Expand Down

0 comments on commit dbca58f

Please sign in to comment.