Skip to content

Commit

Permalink
Bugfix: sanitization-only filters should still work
Browse files Browse the repository at this point in the history
Closes #413
  • Loading branch information
gjtorikian committed Aug 9, 2024
1 parent ba6ec7f commit 109cc11
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/html_pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ def call(text, context: {}, result: {})

if @node_filters.empty?
instrument("sanitization.html_pipeline", payload) do
result[:output] = Selma::Rewriter.new(sanitizer: @sanitization_config, handlers: @node_filters, options: rewriter_options).rewrite(html)
end unless @convert_filter.nil? # no html, so no sanitization
result[:output] = Selma::Rewriter.new(sanitizer: @sanitization_config, options: rewriter_options).rewrite(html)
end
else
instrument("call_node_filters.html_pipeline", payload) do
@node_filters.each { |filter| filter.context = (filter.context || {}).merge(context) }
Expand Down
2 changes: 1 addition & 1 deletion lib/html_pipeline/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class HTMLPipeline
VERSION = "3.2.1"
VERSION = "3.2.2"
end
18 changes: 18 additions & 0 deletions test/sanitization_filter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,23 @@ def test_sanitization_pipeline_does_not_need_node_filters

assert_equal(result[:output].to_s, expected.chomp)
end

def test_a_sanitization_only_pipeline_works
config = Selma::Sanitizer::Config.freeze_config({
elements: [
"strong",
],
})

pipeline = HTMLPipeline.new(
sanitization_config: config,
)

text = "<p>Some <strong>plain</strong> text</p>"
result = pipeline.call(text)
expected = "Some <strong>plain</strong> text"

assert_equal(result[:output].to_s, expected)
end
end
end

0 comments on commit 109cc11

Please sign in to comment.