From 86981d8b967f7357b26c7e71b325b02bd43d683d Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Mon, 28 Jul 2014 15:57:49 -0700 Subject: [PATCH] Properly ignore jaavscript in href Closes https://github.com/gjtorikian/html-proofer/issues/73 --- lib/html/proofer/checks/links.rb | 1 + spec/html/proofer/fixtures/links/javascript_link.html | 9 +++++++++ spec/html/proofer/links_spec.rb | 6 ++++++ 3 files changed, 16 insertions(+) create mode 100644 spec/html/proofer/fixtures/links/javascript_link.html diff --git a/lib/html/proofer/checks/links.rb b/lib/html/proofer/checks/links.rb index d921cec7..cd5c0867 100644 --- a/lib/html/proofer/checks/links.rb +++ b/lib/html/proofer/checks/links.rb @@ -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? diff --git a/spec/html/proofer/fixtures/links/javascript_link.html b/spec/html/proofer/fixtures/links/javascript_link.html new file mode 100644 index 00000000..a37803b0 --- /dev/null +++ b/spec/html/proofer/fixtures/links/javascript_link.html @@ -0,0 +1,9 @@ + + + + +Click me + + + + diff --git a/spec/html/proofer/links_spec.rb b/spec/html/proofer/links_spec.rb index db5497a1..95cff171 100644 --- a/spec/html/proofer/links_spec.rb +++ b/spec/html/proofer/links_spec.rb @@ -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 }