Commit 419bcf2a0445331fa5c03f17e891c7f48e690882
1 parent
d77120be
Exists in
master
and in
28 other branches
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)
Showing
6 changed files
with
36 additions
and
4 deletions
Show diff stats
app/helpers/application_helper.rb
... | ... | @@ -1401,7 +1401,7 @@ module ApplicationHelper |
1401 | 1401 | end |
1402 | 1402 | |
1403 | 1403 | def filter_html(html, source) |
1404 | - if @plugins | |
1404 | + if @plugins && source.has_macro? | |
1405 | 1405 | html = convert_macro(html, source) |
1406 | 1406 | #TODO This parse should be done through the macro infra, but since there |
1407 | 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 | 100 | options[:title] = _("This block is invisible. Your visitors will not see it.") |
101 | 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 | 105 | box_decorator.block_target(block.box, block) + |
108 | 106 | content_tag('div', | ... | ... |
app/models/article.rb
app/models/block.rb
app/models/raw_html_block.rb
test/unit/application_helper_test.rb
... | ... | @@ -791,6 +791,29 @@ class ApplicationHelperTest < ActiveSupport::TestCase |
791 | 791 | '<br style=\'clear: left;\' /></div>', result |
792 | 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 | 817 | protected |
795 | 818 | include NoosferoTestHelper |
796 | 819 | ... | ... |