From c98d44606a06fd5f75c00c22406685eee42c5f1d Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Thu, 11 Jun 2009 13:16:10 -0500 Subject: [PATCH] Wikilinks with '." in the Page Name Rails won't let you put "." in the page name. This prevents creating new-page Wikilinks with such names. --- lib/url_generator.rb | 1 + public/stylesheets/instiki.css | 10 ++++++++++ test/test_helper.rb | 1 + test/unit/page_test.rb | 14 ++++++++++---- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/url_generator.rb b/lib/url_generator.rb index 3d2f38f1..d574f7f4 100644 --- a/lib/url_generator.rb +++ b/lib/url_generator.rb @@ -87,6 +87,7 @@ class UrlGenerator < AbstractUrlGenerator end def page_link(mode, name, text, web_address, known_page) + return %{Illegal link (contains a '.'): [[#{text}]]} if text.include?('.') case mode when :export if known_page diff --git a/public/stylesheets/instiki.css b/public/stylesheets/instiki.css index 5be36371..39457c10 100644 --- a/public/stylesheets/instiki.css +++ b/public/stylesheets/instiki.css @@ -393,6 +393,16 @@ margin:0; padding:0; } +span.wikilink-error { + border: solid 2px red; + background-color: pink; +} + +span.wikilink-error b { + font-size: 80%; + color: #009; +} + merror {display:inline;font-size:1em;} math[display=block] {overflow:auto;} math { white-space: nowrap } diff --git a/test/test_helper.rb b/test/test_helper.rb index 383b5bf1..76302762 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -127,6 +127,7 @@ class StubUrlGenerator < AbstractUrlGenerator def page_link(mode, name, text, web_address, known_page) link = CGI.escape(name) + return %{Illegal link (contains a '.'): [[#{text}]]} if text.include?('.') case mode when :export if known_page then %{#{text}} diff --git a/test/unit/page_test.rb b/test/unit/page_test.rb index 92fbbc91..3011e21f 100644 --- a/test/unit/page_test.rb +++ b/test/unit/page_test.rb @@ -127,7 +127,7 @@ class PageTest < ActiveSupport::TestCase def test_revise_changes_references_from_wanted_to_linked_for_redirected_pages web = Web.find(1) new_page = Page.new(:web => web, :name => 'NewPage') - new_page.revise('Reference to HappyPage, and to WantedPage2', 'NewPage', Time.now, 'AlexeyVerkhovsky', + new_page.revise('Reference to HappyPage, and to WantedPage2', 'NewPage', Time.local(2004, 4, 5, 17, 56), 'AlexeyVerkhovsky', test_renderer) references = new_page.wiki_references(true) @@ -156,15 +156,21 @@ class PageTest < ActiveSupport::TestCase assert_equal 'WantedPage2', references[1].referenced_name assert_equal WikiReference::WANTED_PAGE, references[1].link_type - new_page.revise('Reference to HappyPage', 'NewPage', Time.now, 'AlexeyVerkhovsky', + new_page.revise('Reference to HappyPage and to WantedPage2.pdf and [[foo.pdf]]', 'NewPage', Time.now, 'AlexeyVerkhovsky', test_renderer) references = new_page.wiki_references(true) - assert_match( "Reference to Happy Page", + assert_equal( "

Reference to Happy Page" + + " and to Wanted Page2?.pdf " + + "and Illegal link (contains a '.'): [[foo.pdf]]

", test_renderer(new_page.revisions.last).display_content(true) ) - assert_equal 1, references.size + assert_equal 3, references.size # now it works. assert_equal 'HappyPage', references[0].referenced_name assert_equal WikiReference::LINKED_PAGE, references[0].link_type + assert_equal 'WantedPage2', references[1].referenced_name + assert_equal WikiReference::WANTED_PAGE, references[1].link_type + assert_equal 'foo.pdf', references[2].referenced_name + assert_equal WikiReference::WANTED_PAGE, references[1].link_type end def test_rollback