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

Correct missing method implementation #401

Merged
merged 1 commit into from
Apr 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
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