diff --git a/lib/chunks/include.rb b/lib/chunks/include.rb index 81d1a9b8..18470260 100644 --- a/lib/chunks/include.rb +++ b/lib/chunks/include.rb @@ -36,7 +36,8 @@ class Include < WikiChunk::WikiReference else raise "Unsupported rendering mode #{@mode.inspect}" end - @content.merge_chunks(included_content) + # redirects and categories of included pages should not be inherited + @content.merge_chunks(included_content.delete_chunks!([Redirect, Category])) clear_include_list return included_content.pre_rendered else diff --git a/lib/wiki_content.rb b/lib/wiki_content.rb index 95e04271..2f538443 100644 --- a/lib/wiki_content.rb +++ b/lib/wiki_content.rb @@ -185,6 +185,16 @@ class WikiContent < ActiveSupport::SafeBuffer end end + def delete_chunks!(types) + types.each do |t| + @chunks_by_type[t].each do |c| + @pre_rendered.sub!(c.mask, '') if @pre_rendered + @chunks.delete(c) + end + end + self + end + def pre_render! unless @pre_rendered @chunks_by_type[Include].each{|chunk| chunk.unmask } diff --git a/test/unit/page_renderer_test.rb b/test/unit/page_renderer_test.rb index 5931a53b..d4d9ca31 100644 --- a/test/unit/page_renderer_test.rb +++ b/test/unit/page_renderer_test.rb @@ -743,7 +743,36 @@ END_THM assert_equal WikiReference::INCLUDED_PAGE, references[0].link_type end - def test_references_creation_categories + def test_references_creation_redirects + new_page = @web.add_page('NewPage', '[[!redirects OtherPage]]', + Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', x_test_renderer) + + references = new_page.wiki_references(true) + assert_equal 1, references.size + assert_equal 'OtherPage', references[0].referenced_name + assert_equal WikiReference::REDIRECTED_PAGE, references[0].link_type + end + + def test_references_creation_redirects_in_included_page + new_page = @web.add_page('NewPage', "[[!redirects OtherPage]]\ncategory: plants", + Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', x_test_renderer) + second_page = @web.add_page('SecondPage', '[[!include NewPage]]', + Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', x_test_renderer) + + references = new_page.wiki_references(true) + assert_equal 2, references.size + assert_equal 'OtherPage', references[0].referenced_name + assert_equal WikiReference::REDIRECTED_PAGE, references[0].link_type + assert_equal 'plants', references[1].referenced_name + assert_equal WikiReference::CATEGORY, references[1].link_type + + references = second_page.wiki_references(true) + assert_equal 1, references.size + assert_equal 'NewPage', references[0].referenced_name + assert_equal WikiReference::INCLUDED_PAGE, references[0].link_type + end + + def test_references_creation_categories new_page = @web.add_page('NewPage', "Foo\ncategory: NewPageCategory", Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', x_test_renderer)