Add nofollow when host is missing
This commit is contained in:
parent
19ac5369c5
commit
31b9ec672f
|
@ -27,7 +27,7 @@ class Markdowner
|
|||
|
||||
# make links have rel=nofollow
|
||||
ng.css("a").each do |h|
|
||||
h[:rel] = "nofollow" unless h[:href].starts_with?("/")
|
||||
h[:rel] = "nofollow" unless URI.parse(h[:href]).host.nil?
|
||||
end
|
||||
|
||||
ng.at_css("body").inner_html
|
||||
|
|
|
@ -35,4 +35,17 @@ describe Markdowner do
|
|||
"<p>hi <a href=\"http://example.com/@blahblah/\" rel=\"nofollow\">" <<
|
||||
"test</a></p>"
|
||||
end
|
||||
|
||||
it "correctly adds nofollow" do
|
||||
Markdowner.to_html("[ex](http://example.com)").should ==
|
||||
"<p><a href=\"http://example.com\" rel=\"nofollow\">" <<
|
||||
"ex</a></p>"
|
||||
|
||||
Markdowner.to_html("[ex](//example.com)").should ==
|
||||
"<p><a href=\"//example.com\" rel=\"nofollow\">" <<
|
||||
"ex</a></p>"
|
||||
|
||||
Markdowner.to_html("[ex](/u/abc)").should ==
|
||||
"<p><a href=\"/u/abc\">ex</a></p>"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue