From d31e6afca343e69713c6e0d9cc6e4d756bf3fc07 Mon Sep 17 00:00:00 2001 From: Jamie Oliver Date: Wed, 29 May 2013 19:24:28 +0100 Subject: [PATCH] Improve handling of subdirectories containing spaces --- lib/gollum-lib/page.rb | 15 +++++----- test/test_wiki.rb | 64 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 8 deletions(-) diff --git a/lib/gollum-lib/page.rb b/lib/gollum-lib/page.rb index 2abea5aae..600ad99a1 100644 --- a/lib/gollum-lib/page.rb +++ b/lib/gollum-lib/page.rb @@ -390,16 +390,15 @@ def find(name, version, dir = nil, exact = false) # Returns a Gollum::Page or nil if the page could not be found. def find_page_in_tree(map, name, checked_dir = nil, exact = false) return nil if !map || name.to_s.empty? - if checked_dir = BlobEntry.normalize_dir(checked_dir) - checked_dir.downcase! - end + checked_dir = BlobEntry.normalize_dir(checked_dir) checked_dir = '' if exact && checked_dir.nil? + name = ::File.join(checked_dir, name) if checked_dir map.each do |entry| next if entry.name.to_s.empty? - next unless checked_dir.nil? || entry.dir.downcase == checked_dir - next unless page_match(name, entry.name) + path = checked_dir ? ::File.join(entry.dir, entry.name) : entry.name + next unless page_match(name, path) return entry.page(@wiki, @version) end @@ -435,11 +434,11 @@ def tree_path(treemap, tree) # Compare the canonicalized versions of the two names. # # name - The human or canonical String page name. - # filename - the String filename on disk (including extension). + # path - the String path on disk (including file extension). # # Returns a Boolean. - def page_match(name, filename) - if match = self.class.valid_filename?(filename) + def page_match(name, path) + if match = self.class.valid_filename?(path) @wiki.ws_subs.each do |sub| return true if Page.cname(name).downcase == Page.cname(match, sub).downcase end diff --git a/test/test_wiki.rb b/test/test_wiki.rb index e0a25d367..c5a65c8ae 100644 --- a/test/test_wiki.rb +++ b/test/test_wiki.rb @@ -585,6 +585,16 @@ assert_renamed source, @wiki.page("C") end + test "rename page containing space without directories" do + # Make sure renames involving spaces work with relative paths. + source = @wiki.page("B") + + # B.md => C D.md + assert @wiki.rename_page(source, "C D", rename_commit_details) + + assert_renamed source, @wiki.page("C D") + end + test "rename page with subdirs" do # Make sure renames in subdirectories happen ok source = @wiki.paged("H", "G") @@ -595,6 +605,16 @@ assert_renamed source, @wiki.paged("F", "G") end + test "rename page containing space with subdir" do + # Make sure renames involving spaces in subdirectories happen ok + source = @wiki.paged("H", "G") + + # G/H.md => G/F H.md + assert @wiki.rename_page(source, "G/F H", rename_commit_details) + + assert_renamed source, @wiki.paged("F H", "G") + end + test "rename page absolute path is still no-act" do # Make sure renames don't do anything if the name is the same. @@ -622,6 +642,16 @@ assert_renamed source, @wiki.page("C") end + test "rename page with space absolute directory" do + # Make sure renames involving spaces work with absolute paths. + source = @wiki.page("B") + + # B.md => C D.md + assert @wiki.rename_page(source, "/C D", rename_commit_details) + + assert_renamed source, @wiki.page("C D") + end + test "rename page absolute directory with subdirs" do # Make sure renames in subdirectories happen ok source = @wiki.paged("H", "G") @@ -632,6 +662,16 @@ assert_renamed source, @wiki.paged("F", "G") end + test "rename page containing space absolute directory with subdir" do + # Make sure renames involving spaces in subdirectories happen ok + source = @wiki.paged("H", "G") + + # G/H.md => G/F H.md + assert @wiki.rename_page(source, "/G/F H", rename_commit_details) + + assert_renamed source, @wiki.paged("F H", "G") + end + test "rename page relative directory with new dir creation" do # Make sure renames in subdirectories create more subdirectories ok source = @wiki.paged("H", "G") @@ -644,6 +684,18 @@ assert_renamed source, new_page end + test "rename page relative directory with new dir creation containing space" do + # Make sure renames involving spaces in subdirectories create more subdirectories ok + source = @wiki.paged("H", "G") + + # G/H.md => G/K L/F.md + assert k = @wiki.rename_page(source, "K L/F", rename_commit_details) + + new_page = @wiki.paged("F", "K L") + assert_not_nil new_page + assert_renamed source, new_page + end + test "rename page absolute directory with subdir creation" do # Make sure renames in subdirectories create more subdirectories ok source = @wiki.paged("H", "G") @@ -656,6 +708,18 @@ assert_renamed source, new_page end + test "rename page absolute directory with subdir creation containing space" do + # Make sure renames involving spaces in subdirectories create more subdirectories ok + source = @wiki.paged("H", "G") + + # G/H.md => G/K L/F.md + assert @wiki.rename_page(source, "/G/K L/F", rename_commit_details) + + new_page = @wiki.paged("F", "G/K L") + assert_not_nil new_page + assert_renamed source, new_page + end + def assert_renamed(page_source, page_target) @wiki.clear_cache assert_nil @wiki.paged(page_source.name, page_source.path)