Skip to content

Commit 61cbe4c

Browse files
committed
Correct missing method implementation
1 parent e1328b4 commit 61cbe4c

File tree

5 files changed

+69
-3
lines changed

5 files changed

+69
-3
lines changed

lib/html_pipeline/text_filter/image_filter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class TextFilter
99
# <img src="http://example.com/test.jpg" alt=""/>.
1010

1111
class ImageFilter < TextFilter
12-
def call(text)
12+
def call(text, context: {}, result: {})
1313
text.gsub(%r{(https|http)?://.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?}i) do |match|
1414
%(<img src="#{match}" alt=""/>)
1515
end

lib/html_pipeline/text_filter/plain_text_input_filter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class TextFilter
55
# Simple filter for plain text input. HTML escapes the text input and wraps it
66
# in a div.
77
class PlainTextInputFilter < TextFilter
8-
def call(text)
8+
def call(text, context: {}, result: {})
99
"<div>#{CGI.escapeHTML(text)}</div>"
1010
end
1111
end

lib/html_pipeline/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
class HTMLPipeline
4-
VERSION = "3.1.0"
4+
VERSION = "3.1.1"
55
end

test/html_pipeline/text_filter/plain_text_input_filter_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,15 @@ def test_html_escapes_plain_text_input
2727
doc.to_s,
2828
)
2929
end
30+
31+
def test_works_within_complete_pipeline
32+
pipeline = HTMLPipeline.new(text_filters: [HTMLPipeline::TextFilter::PlainTextInputFilter.new])
33+
result = pipeline.call("See: <http://example.org>")
34+
35+
assert_equal(
36+
"<div>See: &lt;http://example.org&gt;</div>",
37+
result[:output],
38+
)
39+
end
3040
end
3141
end

test/text_filter_test.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
require "html_pipeline/text_filter/image_filter"
5+
6+
ImageFilter = HTMLPipeline::TextFilter::ImageFilter
7+
8+
class HTMLPipeline
9+
class ImageFilterTest < Minitest::Test
10+
def setup
11+
@filter = ImageFilter
12+
end
13+
14+
def test_jpg
15+
assert_equal(
16+
%(<img src="http://example.com/test.jpg" alt=""/>),
17+
@filter.call(%(http://example.com/test.jpg)),
18+
)
19+
end
20+
21+
def test_jpeg
22+
assert_equal(
23+
%(<img src="http://example.com/test.jpeg" alt=""/>),
24+
@filter.call(%(http://example.com/test.jpeg)),
25+
)
26+
end
27+
28+
def test_bmp
29+
assert_equal(
30+
%(<img src="http://example.com/test.bmp" alt=""/>),
31+
@filter.call(%(http://example.com/test.bmp)),
32+
)
33+
end
34+
35+
def test_gif
36+
assert_equal(
37+
%(<img src="http://example.com/test.gif" alt=""/>),
38+
@filter.call(%(http://example.com/test.gif)),
39+
)
40+
end
41+
42+
def test_png
43+
assert_equal(
44+
%(<img src="http://example.com/test.png" alt=""/>),
45+
@filter.call(%(http://example.com/test.png)),
46+
)
47+
end
48+
49+
def test_https_url
50+
assert_equal(
51+
%(<img src="https://example.com/test.png" alt=""/>),
52+
@filter.call(%(https://example.com/test.png)),
53+
)
54+
end
55+
end
56+
end

0 commit comments

Comments
 (0)