diff --git a/lib/url_generator.rb b/lib/url_generator.rb index dbc68dd3..8f12e535 100644 --- a/lib/url_generator.rb +++ b/lib/url_generator.rb @@ -17,6 +17,7 @@ class AbstractUrlGenerator else known_page = web.has_file?(name) description = web.description(name) + description = CGI.escapeHTML(CGI.unescapeHTML(description)) if description end if (text == name) text = description || text @@ -29,7 +30,7 @@ class AbstractUrlGenerator when :show page_link(mode, name, text, web.address, known_page) when :file - file_link(mode, name, text, web.address, known_page) + file_link(mode, name, text, web.address, known_page, description) when :pic pic_link(mode, name, text, web.address, known_page) else @@ -43,11 +44,11 @@ class UrlGenerator < AbstractUrlGenerator private - def file_link(mode, name, text, web_address, known_file) + def file_link(mode, name, text, web_address, known_file, description) case mode when :export if known_file - %{#{text}} + %{#{text}} else %{#{text}} end @@ -55,7 +56,7 @@ class UrlGenerator < AbstractUrlGenerator if known_file href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file', :id => name - %{#{text}} + %{#{text}} else %{#{text}} end @@ -63,7 +64,7 @@ class UrlGenerator < AbstractUrlGenerator href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file', :id => name if known_file - %{#{text}} + %{#{text}} else %{#{text}?} end diff --git a/test/test_helper.rb b/test/test_helper.rb index d8b08a70..8cb0b374 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -102,18 +102,18 @@ class StubUrlGenerator < AbstractUrlGenerator super(:doesnt_need_controller) end - def file_link(mode, name, text, web_name, known_file) + def file_link(mode, name, text, web_name, known_file, description) link = CGI.escape(name) case mode when :export - if known_file then %{#{text}} + if known_file then %{#{text}} else %{#{text}} end when :publish - if known_file then %{#{text}} + if known_file then %{#{text}} else %{#{text}} end else if known_file - %{#{text}} + %{#{text}} else %{#{text}?} end diff --git a/test/unit/page_renderer_test.rb b/test/unit/page_renderer_test.rb index 17ea2fa8..471c4c07 100644 --- a/test/unit/page_renderer_test.rb +++ b/test/unit/page_renderer_test.rb @@ -299,7 +299,7 @@ class PageRendererTest < Test::Unit::TestCase '[[doc.pdf:file]]') end - def test_link_to_pic + def test_link_to_pic_and_file WikiFile.delete_all require 'fileutils' FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*") @@ -310,6 +310,31 @@ class PageRendererTest < Test::Unit::TestCase assert_markup_parsed_as( '
', '[[square.jpg:pic]]') + assert_markup_parsed_as( + '', + '[[square.jpg|Blue Square:file]]') + assert_markup_parsed_as( + '', + '[[square.jpg:file]]') + end + + def test_link_to_pic_and_file_null_desc + WikiFile.delete_all + require 'fileutils' + FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*") + @web.wiki_files.create(:file_name => 'square.jpg', :description => '', :content => 'never mind') + assert_markup_parsed_as( + '', + '[[square.jpg|Blue Square:pic]]') + assert_markup_parsed_as( + '', + '[[square.jpg:pic]]') + assert_markup_parsed_as( + '', + '[[square.jpg|Blue Square:file]]') + assert_markup_parsed_as( + '', + '[[square.jpg:file]]') end def test_link_to_non_existant_pic