From 419bcf2a0445331fa5c03f17e891c7f48e690882 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Thu, 31 Oct 2013 15:44:19 -0300 Subject: [PATCH] filter_html: parse only sources that have macros --- app/helpers/application_helper.rb | 2 +- app/helpers/boxes_helper.rb | 4 +--- app/models/article.rb | 4 ++++ app/models/block.rb | 4 ++++ app/models/raw_html_block.rb | 3 +++ test/unit/application_helper_test.rb | 23 +++++++++++++++++++++++ 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d193b73..07e41ad 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1401,7 +1401,7 @@ module ApplicationHelper end def filter_html(html, source) - if @plugins + if @plugins && source.has_macro? html = convert_macro(html, source) #TODO This parse should be done through the macro infra, but since there # are old things that do not support it we are keeping this hot spot. diff --git a/app/helpers/boxes_helper.rb b/app/helpers/boxes_helper.rb index 7bf7a74..6f08a83 100644 --- a/app/helpers/boxes_helper.rb +++ b/app/helpers/boxes_helper.rb @@ -100,9 +100,7 @@ module BoxesHelper options[:title] = _("This block is invisible. Your visitors will not see it.") end - if @controller.send(:content_editor?) - result = filter_html(result, block) - end + result = filter_html(result, block) box_decorator.block_target(block.box, block) + content_tag('div', diff --git a/app/models/article.rb b/app/models/article.rb index 3bb49c6..4f564d8 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -673,6 +673,10 @@ class Article < ActiveRecord::Base delegate :region, :region_id, :environment, :environment_id, :to => :profile, :allow_nil => true + def has_macro? + true + end + private def sanitize_tag_list diff --git a/app/models/block.rb b/app/models/block.rb index 9fab33b..5231153 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -138,4 +138,8 @@ class Block < ActiveRecord::Base 4.hours end + def has_macro? + false + end + end diff --git a/app/models/raw_html_block.rb b/app/models/raw_html_block.rb index a403b51..f370077 100644 --- a/app/models/raw_html_block.rb +++ b/app/models/raw_html_block.rb @@ -10,4 +10,7 @@ class RawHTMLBlock < Block (title.blank? ? '' : block_title(title)).html_safe + html.to_s.html_safe end + def has_macro? + true + end end diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index e96507e..bc28cd3 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -791,6 +791,29 @@ class ApplicationHelperTest < ActiveSupport::TestCase '
', result end + should 'not filter html if source does not have macros' do + class Plugin1 < Noosfero::Plugin + end + + class Plugin1::Macro1 < Noosfero::Plugin::Macro + def parse(params, inner_html, source) + 'Test1' + end + end + + environment = Environment.default + environment.enable_plugin(Plugin1) + @plugins = Noosfero::Plugin::Manager.new(environment, self) + macro1_name = Plugin1::Macro1.identifier + source = mock + source.stubs(:has_macro?).returns(false) + + html = "
" + parsed_html = filter_html(html, source) + + assert_no_match /Test1/, parsed_html + end + protected include NoosferoTestHelper -- libgit2 0.21.2