Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: sanitization-only filters should still work #414

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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