diff --git a/app/models/chunks/chunk.rb b/app/models/chunks/chunk.rb index efd7ecfe..82d0d7fa 100755 --- a/app/models/chunks/chunk.rb +++ b/app/models/chunks/chunk.rb @@ -24,22 +24,6 @@ module Chunk end end - def pre_mask - "chunk#{self.object_id}#{self.class.to_s.delete(':').downcase}start" - end - - def post_mask - "chunk#{self.object_id}end" - end - - def bracketing_mask(content) - "#{pre_mask} #{content} #{post_mask}" - end - - def bracketing_mask_regexp - Regexp.new("#{pre_mask} (.*)[ \n]#{post_mask}") - end - def mask(content) "chunk#{self.object_id}#{self.class.to_s.delete(':').downcase}chunk" end diff --git a/app/models/chunks/wiki.rb b/app/models/chunks/wiki.rb index 673deaa4..c69f160f 100755 --- a/app/models/chunks/wiki.rb +++ b/app/models/chunks/wiki.rb @@ -38,23 +38,28 @@ module WikiChunk # By default, no escaped text def escaped_text() nil end - # FIXME: do not use the bracketing mask - URI chunk thinks that 'index.jpg' - # contains URL http://index.jp - # Replace link with a mask, but if the word is escaped, then don't replace it - def mask(content) escaped_text || bracketing_mask(link_text) end + def mask(content) + escaped_text || super(content) + end - def regexp() bracketing_mask_regexp end - - def revert(content) content.sub!(regexp, text) end + def revert(content) content.sub!(mask(content), text) end # Do not keep this chunk if it is escaped. # Otherwise, pass the link procedure a page_name and link_text and # get back a string of HTML to replace the mask with. def unmask(content) - return nil if escaped_text - return self if content.sub!(regexp) do |match| - content.page_link(page_name, $1, link_type) + if escaped_text + return self + else + chunk_found = content.sub!(mask(content)) do |match| + content.page_link(page_name, link_text, link_type) + end + if chunk_found + return self + else + return nil + end end end @@ -78,7 +83,9 @@ module WikiChunk @textile_link_suffix, @escape, @page_name = match_data[1..3] end - def escaped_text() (@escape.nil? ? nil : page_name) end + def escaped_text + page_name unless @escape.nil? + end def link_text() WikiWords.separate(page_name) end end diff --git a/app/models/web.rb b/app/models/web.rb index a009afb2..41de594d 100755 --- a/app/models/web.rb +++ b/app/models/web.rb @@ -46,7 +46,7 @@ class Web # on the render mode in options and whether the page exists # in the this web. def make_link(name, text = nil, options = {}) - text = text || WikiWords.separate(name) + text = CGI.escapeHTML(text || WikiWords.separate(name)) mode = options[:mode] link_type = options[:link_type] || 'show' case link_type diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb index b596b2ff..868d057e 100755 --- a/app/models/wiki_content.rb +++ b/app/models/wiki_content.rb @@ -39,7 +39,7 @@ require 'chunks/nowiki' # UPDATED: 22nd May 2004 class WikiContent < String - PRE_ENGINE_ACTIONS = [ NoWiki, Category, Include, URIChunk, LocalURIChunk, WikiChunk::Link, + PRE_ENGINE_ACTIONS = [ NoWiki, Category, Include, WikiChunk::Link, URIChunk, LocalURIChunk, WikiChunk::Word ] POST_ENGINE_ACTIONS = [ Literal::Pre, Literal::Tags ] DEFAULT_OPTS = { @@ -90,7 +90,6 @@ class WikiContent < String def render!(chunk_types) @chunks = [] chunk_types.each { |chunk_type| chunk_type.apply_to(self) } - @rendered = @chunks.map { |chunk| chunk.unmask(self) }.compact (@chunks - @rendered).each { |chunk| chunk.revert(self) } end diff --git a/test/unit/revision_test.rb b/test/unit/revision_test.rb index 2bb60c94..68798135 100755 --- a/test/unit/revision_test.rb +++ b/test/unit/revision_test.rb @@ -16,7 +16,7 @@ class RevisionTest < Test::Unit::TestCase end @revision = Revision.new(@page, 1, - 'HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \\OverThere -- ' + + 'HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \OverThere -- ' + 'see SmartEngine in that SmartEngineGUI', Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson') end @@ -40,7 +40,7 @@ class RevisionTest < Test::Unit::TestCase 'His Way? ' + 'though My Way OverThere—see ' + 'Smart Engine in that ' + - 'Smart Engine GUI' + + 'Smart Engine GUI' + '?

', @revision.display_content end @@ -108,6 +108,11 @@ class RevisionTest < Test::Unit::TestCase 'That is some Stylish Emphasis') end + def test_content_with_escaped_wikiword + # there should be no wiki link + assert_markup_parsed_as('

WikiWord

', '\WikiWord') + end + def test_content_with_pre_blocks assert_markup_parsed_as( 'A class SmartEngine end would not mark up
CodeBlocks
', @@ -155,7 +160,7 @@ class RevisionTest < Test::Unit::TestCase 'His Way though ' + 'My Way OverThere—see ' + 'Smart Engine in that ' + - 'Smart Engine GUI

', + 'Smart Engine GUI

', @revision.display_content_for_export end @@ -179,8 +184,8 @@ class RevisionTest < Test::Unit::TestCase def test_difficult_wiki_words @revision.content = "[[It's just awesome GUI!]]" - assert_equal "

It’s just awesome GUI" + - "!?

", + assert_equal "

It's just awesome GUI!" + + "?

", @revision.display_content end @@ -205,7 +210,7 @@ class RevisionTest < Test::Unit::TestCase end def test_link_to_pic - assert_markup_parsed_as( + assert_markup_parsed_as( '

Square

', '[[square.jpg|Square:pic]]') assert_markup_parsed_as( diff --git a/test/unit/web_test.rb b/test/unit/web_test.rb index b58afa3c..9dc906ec 100755 --- a/test/unit/web_test.rb +++ b/test/unit/web_test.rb @@ -84,7 +84,7 @@ class WebTest < Test::Unit::TestCase # Escaping special characters in the name assert_equal( - 'Smith & Wesson?', + 'Smith & Wesson?', @web.make_link('Smith & Wesson')) # optionally using text as the link text