From 109cc11031fe139ff288b3f2ba5979ba2a8214cb Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Fri, 9 Aug 2024 11:55:39 -0400 Subject: [PATCH] Bugfix: sanitization-only filters should still work Closes https://github.com/gjtorikian/html-pipeline/issues/413 --- lib/html_pipeline.rb | 4 ++-- lib/html_pipeline/version.rb | 2 +- test/sanitization_filter_test.rb | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/html_pipeline.rb b/lib/html_pipeline.rb index 523ec63c..93d0663d 100644 --- a/lib/html_pipeline.rb +++ b/lib/html_pipeline.rb @@ -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) } diff --git a/lib/html_pipeline/version.rb b/lib/html_pipeline/version.rb index 7d8e20a4..617f4bda 100644 --- a/lib/html_pipeline/version.rb +++ b/lib/html_pipeline/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class HTMLPipeline - VERSION = "3.2.1" + VERSION = "3.2.2" end diff --git a/test/sanitization_filter_test.rb b/test/sanitization_filter_test.rb index fd81c04d..93987d46 100644 --- a/test/sanitization_filter_test.rb +++ b/test/sanitization_filter_test.rb @@ -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 = "

Some plain text

" + result = pipeline.call(text) + expected = "Some plain text" + + assert_equal(result[:output].to_s, expected) + end end end