Repository: gjtorikian/html-pipeline (Ruby)

Issue:
Error when passing instance of `TextFilter` class to `text_filters` option
When passing an instance of the `TextFilter` class to the `text_filters` option as per the sample code, it results in a `wrong number of arguments (given 2, expected 1)` error.

**Steps to Reproduce**

```ruby
pipeline = HTMLPipeline.new(text_filters: [ HTMLPipeline::TextFilter::PlainTextInputFilter.new])
pipeline.call('test')
```

**Workaround**

```ruby
pipeline = HTMLPipeline.new(text_filters: [ HTMLPipeline::TextFilter::PlainTextInputFilter])
pipeline.call('test')
```

**Additional Information**
https://github.com/gjtorikian/html-pipeline/blob/e1328b4763dd56a83abaa1746ba8555e0e80ec04/lib/html_pipeline.rb#L213


Discussion:
Which version of `html-pipeline` is this? Recently there was a change to this exact behavior—the latest version is 3.1.0. Could you try your example with that?
Thank you for your response.
I'm using 3.1.0.
The issue arises because although keyword arguments are being passed to the call method, the TextFilter class's call method only accepts the text argument.

https://github.com/gjtorikian/html-pipeline/blob/e1328b4763dd56a83abaa1746ba8555e0e80ec04/lib/html_pipeline.rb#L213

https://github.com/gjtorikian/html-pipeline/blob/e1328b4763dd56a83abaa1746ba8555e0e80ec04/lib/html_pipeline/text_filter/plain_text_input_filter.rb#L8
Gah, thank you for noticing that. 3.1.1 is released, fixing this. 



Patch:
diff --git a/lib/html_pipeline/text_filter/image_filter.rb b/lib/html_pipeline/text_filter/image_filter.rb
index b95045dd..59e2bd66 100644
--- a/lib/html_pipeline/text_filter/image_filter.rb
+++ b/lib/html_pipeline/text_filter/image_filter.rb
@@ -9,7 +9,7 @@ class TextFilter
     #   <img src="http://example.com/test.jpg" alt=""/>.
 
     class ImageFilter < TextFilter
-      def call(text)
+      def call(text, context: {}, result: {})
         text.gsub(%r{(https|http)?://.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?}i) do |match|
           %(<img src="#{match}" alt=""/>)
         end
diff --git a/lib/html_pipeline/text_filter/plain_text_input_filter.rb b/lib/html_pipeline/text_filter/plain_text_input_filter.rb
index 6a796662..ab8f015d 100644
--- a/lib/html_pipeline/text_filter/plain_text_input_filter.rb
+++ b/lib/html_pipeline/text_filter/plain_text_input_filter.rb
@@ -5,7 +5,7 @@ class TextFilter
     # Simple filter for plain text input. HTML escapes the text input and wraps it
     # in a div.
     class PlainTextInputFilter < TextFilter
-      def call(text)
+      def call(text, context: {}, result: {})
         "<div>#{CGI.escapeHTML(text)}</div>"
       end
     end
diff --git a/lib/html_pipeline/version.rb b/lib/html_pipeline/version.rb
index 325f4c46..07f6fc2f 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.1.0"
+  VERSION = "3.1.1"
 end


Test patch:
diff --git a/test/html_pipeline/text_filter/plain_text_input_filter_test.rb b/test/html_pipeline/text_filter/plain_text_input_filter_test.rb
index d53db0aa..0454c6f6 100644
--- a/test/html_pipeline/text_filter/plain_text_input_filter_test.rb
+++ b/test/html_pipeline/text_filter/plain_text_input_filter_test.rb
@@ -27,5 +27,15 @@ def test_html_escapes_plain_text_input
         doc.to_s,
       )
     end
+
+    def test_works_within_complete_pipeline
+      pipeline = HTMLPipeline.new(text_filters: [HTMLPipeline::TextFilter::PlainTextInputFilter.new])
+      result = pipeline.call("See: <http://example.org>")
+
+      assert_equal(
+        "<div>See: &lt;http://example.org&gt;</div>",
+        result[:output],
+      )
+    end
   end
 end
diff --git a/test/text_filter_test.rb b/test/text_filter_test.rb
new file mode 100644
index 00000000..f2e365ff
--- /dev/null
+++ b/test/text_filter_test.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+require "test_helper"
+require "html_pipeline/text_filter/image_filter"
+
+ImageFilter = HTMLPipeline::TextFilter::ImageFilter
+
+class HTMLPipeline
+  class ImageFilterTest < Minitest::Test
+    def setup
+      @filter = ImageFilter
+    end
+
+    def test_jpg
+      assert_equal(
+        %(<img src="http://example.com/test.jpg" alt=""/>),
+        @filter.call(%(http://example.com/test.jpg)),
+      )
+    end
+
+    def test_jpeg
+      assert_equal(
+        %(<img src="http://example.com/test.jpeg" alt=""/>),
+        @filter.call(%(http://example.com/test.jpeg)),
+      )
+    end
+
+    def test_bmp
+      assert_equal(
+        %(<img src="http://example.com/test.bmp" alt=""/>),
+        @filter.call(%(http://example.com/test.bmp)),
+      )
+    end
+
+    def test_gif
+      assert_equal(
+        %(<img src="http://example.com/test.gif" alt=""/>),
+        @filter.call(%(http://example.com/test.gif)),
+      )
+    end
+
+    def test_png
+      assert_equal(
+        %(<img src="http://example.com/test.png" alt=""/>),
+        @filter.call(%(http://example.com/test.png)),
+      )
+    end
+
+    def test_https_url
+      assert_equal(
+        %(<img src="https://example.com/test.png" alt=""/>),
+        @filter.call(%(https://example.com/test.png)),
+      )
+    end
+  end
+end