Skip to content

Commit

Permalink
Correct missing method implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Apr 9, 2024
1 parent e1328b4 commit 61cbe4c
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/html_pipeline/text_filter/image_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/html_pipeline/text_filter/plain_text_input_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.1.0"
VERSION = "3.1.1"
end
10 changes: 10 additions & 0 deletions test/html_pipeline/text_filter/plain_text_input_filter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
56 changes: 56 additions & 0 deletions test/text_filter_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 61cbe4c

Please sign in to comment.