From 903c4b6bdd0efb6e743c00832f0863449678151c Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Tue, 23 Aug 2011 14:35:27 -0500 Subject: [PATCH] Pre Chunk-Handler gets confused when XML parser converts empty elements to short-tag syntax. Reported by Andrew Stacey. --- lib/chunks/literal.rb | 2 +- test/unit/chunks/nowiki_test.rb | 12 ++++++++++++ test/unit/page_renderer_test.rb | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/chunks/literal.rb b/lib/chunks/literal.rb index da17c9b9..9602f2ad 100644 --- a/lib/chunks/literal.rb +++ b/lib/chunks/literal.rb @@ -18,7 +18,7 @@ module Literal # A literal chunk that protects 'code' and 'pre' tags from wiki rendering. class Pre < AbstractLiteral PRE_BLOCKS = "a|pre|code|math" - PRE_PATTERN = Regexp.new('<('+PRE_BLOCKS+')\b[^>]*?>.*?', Regexp::MULTILINE) + PRE_PATTERN = Regexp.new('<('+PRE_BLOCKS+')\b[^>]*?(>.*?|/>)', Regexp::MULTILINE) def self.pattern() PRE_PATTERN end end diff --git a/test/unit/chunks/nowiki_test.rb b/test/unit/chunks/nowiki_test.rb index bbd00856..96e5bfd3 100755 --- a/test/unit/chunks/nowiki_test.rb +++ b/test/unit/chunks/nowiki_test.rb @@ -56,4 +56,16 @@ class NoWikiTest < Test::Unit::TestCase ) end + def test_sanitize_empty_nowiki + match(NoWiki, "", + :plain_text => '' + ) + end + + def test_sanitize_blank_nowiki + match(NoWiki, "\n", + :plain_text => "\n" + ) + end + end diff --git a/test/unit/page_renderer_test.rb b/test/unit/page_renderer_test.rb index 9e633d96..cbea5c43 100644 --- a/test/unit/page_renderer_test.rb +++ b/test/unit/page_renderer_test.rb @@ -44,6 +44,12 @@ class PageRendererTest < ActiveSupport::TestCase assert_equal %w( HisWay SmartEngineGUI ), x_test_renderer(@revision).unexisting_pages.sort end + def test_wiki_links_after_empty + assert_markup_parsed_as(%{\n

This is a wikilink?.

}, + "\n\nThis is a [[wikilink]].") + end + def test_content_with_wiki_links assert_equal "

His Way? " + "would be My Way " +