Skip to content

Commit

Permalink
Make acts_as_loofah work for JRuby
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Jan 22, 2025
1 parent 754c288 commit 97dc987
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/loofah/xml/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def acts_as_loofah

# TODO: this should to be upstreamed into Nokogiri
def decorate_existing
return if Nokogiri.jruby?
return unless @decorators

@node_cache.each do |node|
Expand Down
3 changes: 3 additions & 0 deletions lib/loofah/xml/document_fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def parse(tags)
module NokogiriExtender
def acts_as_loofah
document.acts_as_loofah
if Nokogiri.jruby?
traverse { |node| document.decorate(node) }
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_acts_as_loofah.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class UnitTestActsAsLoofah < Loofah::TestCase

assert_respond_to(ndoc, :scrub!, "#{subject_class}::Document should be extended")
assert_respond_to(ndoc.at_css("span"), :scrub!, "New child elements should be extended")
assert_respond_to(node, :scrub!, "Existing child elements should be extended")
assert_respond_to(node, :scrub!, "Existing child elements should be extended") unless Nokogiri.jruby?

# scrub behavior
ndoc.scrub!(:prune)
Expand All @@ -45,7 +45,7 @@ class UnitTestActsAsLoofah < Loofah::TestCase

assert_respond_to(nfrag, :scrub!, "#{subject_class}::DocumentFragment should be extended")
assert_respond_to(nfrag.at_css("span"), :scrub!, "New child elements should be extended")
assert_respond_to(node, :scrub!, "Existing child elements should be extended")
assert_respond_to(node, :scrub!, "Existing child elements should be extended") unless Nokogiri.jruby?

# scrub behavior
nfrag.scrub!(:prune)
Expand Down

0 comments on commit 97dc987

Please sign in to comment.