Skip to content

Commit c5912e7

Browse files
authored
Merge pull request #92 from JuanitoFatas/link-sanitizer
Remove href from LinkSanitizer tags list
2 parents 2191bfe + 5d735a7 commit c5912e7

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

lib/rails/html/sanitizer.rb

+7-6
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ def sanitize(html, options = {})
4040
end
4141

4242
# === Rails::Html::LinkSanitizer
43-
# Removes a tags and href attributes leaving only the link text
43+
# Removes +a+ tags and +href+ attributes leaving only the link text.
4444
#
45-
# link_sanitizer = Rails::Html::LinkSanitizer.new
46-
# link_sanitizer.sanitize('<a href="example.com">Only the link text will be kept.</a>')
47-
# # => Only the link text will be kept.
45+
# link_sanitizer = Rails::Html::LinkSanitizer.new
46+
# link_sanitizer.sanitize('<a href="example.com">Only the link text will be kept.</a>')
47+
#
48+
# => 'Only the link text will be kept.'
4849
class LinkSanitizer < Sanitizer
4950
def initialize
5051
@link_scrubber = TargetScrubber.new
51-
@link_scrubber.tags = %w(a href)
52+
@link_scrubber.tags = %w(a)
5253
@link_scrubber.attributes = %w(href)
5354
end
5455

@@ -146,7 +147,7 @@ def allowed_tags(options)
146147

147148
def allowed_attributes(options)
148149
options[:attributes] || self.class.allowed_attributes
149-
end
150+
end
150151
end
151152

152153
WhiteListSanitizer = SafeListSanitizer

test/sanitizer_test.rb

-4
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ def test_strip_links_with_linkception
154154
assert_equal "Magic", link_sanitize("<a href='http://www.rubyonrails.com/'>Mag<a href='http://www.ruby-lang.org/'>ic")
155155
end
156156

157-
def test_strip_links_with_a_tag_in_href
158-
assert_equal "FrrFox", link_sanitize("<href onlclick='steal()'>FrrFox</a></href>")
159-
end
160-
161157
def test_sanitize_form
162158
assert_sanitized "<form action=\"/foo/bar\" method=\"post\"><input></form>", ''
163159
end

0 commit comments

Comments
 (0)