Commit 419bcf2a0445331fa5c03f17e891c7f48e690882

Authored by Rodrigo Souto
1 parent d77120be

filter_html: parse only sources that have macros

This solves every problem related with Hpticot breaking pages since the
parse was happening on the MainBlock too. But this does not changes the
fact tha Hpricot is currently dead and we should move on to nokogiri.

(ActionItem2873)
app/helpers/application_helper.rb
@@ -1401,7 +1401,7 @@ module ApplicationHelper @@ -1401,7 +1401,7 @@ module ApplicationHelper
1401 end 1401 end
1402 1402
1403 def filter_html(html, source) 1403 def filter_html(html, source)
1404 - if @plugins 1404 + if @plugins && source.has_macro?
1405 html = convert_macro(html, source) 1405 html = convert_macro(html, source)
1406 #TODO This parse should be done through the macro infra, but since there 1406 #TODO This parse should be done through the macro infra, but since there
1407 # are old things that do not support it we are keeping this hot spot. 1407 # are old things that do not support it we are keeping this hot spot.
app/helpers/boxes_helper.rb
@@ -100,9 +100,7 @@ module BoxesHelper @@ -100,9 +100,7 @@ module BoxesHelper
100 options[:title] = _("This block is invisible. Your visitors will not see it.") 100 options[:title] = _("This block is invisible. Your visitors will not see it.")
101 end 101 end
102 102
103 - if @controller.send(:content_editor?)  
104 - result = filter_html(result, block)  
105 - end 103 + result = filter_html(result, block)
106 104
107 box_decorator.block_target(block.box, block) + 105 box_decorator.block_target(block.box, block) +
108 content_tag('div', 106 content_tag('div',
app/models/article.rb
@@ -673,6 +673,10 @@ class Article < ActiveRecord::Base @@ -673,6 +673,10 @@ class Article < ActiveRecord::Base
673 673
674 delegate :region, :region_id, :environment, :environment_id, :to => :profile, :allow_nil => true 674 delegate :region, :region_id, :environment, :environment_id, :to => :profile, :allow_nil => true
675 675
  676 + def has_macro?
  677 + true
  678 + end
  679 +
676 private 680 private
677 681
678 def sanitize_tag_list 682 def sanitize_tag_list
app/models/block.rb
@@ -138,4 +138,8 @@ class Block < ActiveRecord::Base @@ -138,4 +138,8 @@ class Block < ActiveRecord::Base
138 4.hours 138 4.hours
139 end 139 end
140 140
  141 + def has_macro?
  142 + false
  143 + end
  144 +
141 end 145 end
app/models/raw_html_block.rb
@@ -10,4 +10,7 @@ class RawHTMLBlock < Block @@ -10,4 +10,7 @@ class RawHTMLBlock < Block
10 (title.blank? ? '' : block_title(title)).html_safe + html.to_s.html_safe 10 (title.blank? ? '' : block_title(title)).html_safe + html.to_s.html_safe
11 end 11 end
12 12
  13 + def has_macro?
  14 + true
  15 + end
13 end 16 end
test/unit/application_helper_test.rb
@@ -791,6 +791,29 @@ class ApplicationHelperTest < ActiveSupport::TestCase @@ -791,6 +791,29 @@ class ApplicationHelperTest < ActiveSupport::TestCase
791 '<br style=\'clear: left;\' /></div>', result 791 '<br style=\'clear: left;\' /></div>', result
792 end 792 end
793 793
  794 + should 'not filter html if source does not have macros' do
  795 + class Plugin1 < Noosfero::Plugin
  796 + end
  797 +
  798 + class Plugin1::Macro1 < Noosfero::Plugin::Macro
  799 + def parse(params, inner_html, source)
  800 + 'Test1'
  801 + end
  802 + end
  803 +
  804 + environment = Environment.default
  805 + environment.enable_plugin(Plugin1)
  806 + @plugins = Noosfero::Plugin::Manager.new(environment, self)
  807 + macro1_name = Plugin1::Macro1.identifier
  808 + source = mock
  809 + source.stubs(:has_macro?).returns(false)
  810 +
  811 + html = "<div class='macro nonEdit' data-macro='#{macro1_name}' data-macro-param='123'></div>"
  812 + parsed_html = filter_html(html, source)
  813 +
  814 + assert_no_match /Test1/, parsed_html
  815 + end
  816 +
794 protected 817 protected
795 include NoosferoTestHelper 818 include NoosferoTestHelper
796 819