Skip to content

Commit

Permalink
Merge pull request #74 from gjtorikian/dont-fail-on-javascript-href
Browse files Browse the repository at this point in the history
Properly ignore jaavscript in href
  • Loading branch information
gjtorikian committed Jul 29, 2014
2 parents 8ad4b51 + 86981d8 commit 4a18fa2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/html/proofer/checks/links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def run
link = Link.new l, "link", self

next if link.ignore?
next if link.href =~ /^javascript:/ # can't put this in ignore? because the URI does not parse

# is it even a valid URL?
unless link.valid?
Expand Down
9 changes: 9 additions & 0 deletions spec/html/proofer/fixtures/links/javascript_link.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>

<body>

<a href="javascript:if(typeof WZXYxe58==typeof alert)WZXYxe58();(function(){var s=document.createElement('link');s.setAttribute('href','/static/css/dyslexia.css');s.setAttribute('rel','stylesheet');s.setAttribute('type','text/css');document.getElementsByTagName('head')[0].appendChild(s);})();">Click me</a>

</body>

</html>
6 changes: 6 additions & 0 deletions spec/html/proofer/links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@
output.should match /tel: is an invalid URL/
end

it 'ignores javascript links' do
javascriptLink = "#{FIXTURES_DIR}/links/javascript_link.html"
output = capture_stderr { HTML::Proofer.new(javascriptLink).run }
output.should == ""
end

it "works for valid links missing the protocol" do
missingProtocolLink = "#{FIXTURES_DIR}/links/link_missing_protocol_valid.html"
output = capture_stderr { HTML::Proofer.new(missingProtocolLink).run }
Expand Down

0 comments on commit 4a18fa2

Please sign in to comment.