diff --git a/extras/markdowner.rb b/extras/markdowner.rb index 7af5fe3..901e3e3 100644 --- a/extras/markdowner.rb +++ b/extras/markdowner.rb @@ -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 diff --git a/spec/models/markdowner_spec.rb b/spec/models/markdowner_spec.rb index 96d66b8..81776c6 100644 --- a/spec/models/markdowner_spec.rb +++ b/spec/models/markdowner_spec.rb @@ -35,4 +35,17 @@ describe Markdowner do "

hi " << "test

" end + + it "correctly adds nofollow" do + Markdowner.to_html("[ex](http://example.com)").should == + "

" << + "ex

" + + Markdowner.to_html("[ex](//example.com)").should == + "

" << + "ex

" + + Markdowner.to_html("[ex](/u/abc)").should == + "

ex

" + end end