Skip to content

Commit

Permalink
Merge pull request #238 from gjtorikian/no-alphabets
Browse files Browse the repository at this point in the history
Ignore cases when checking internal IDs
  • Loading branch information
gjtorikian committed Sep 1, 2015
2 parents 37b9209 + 2680593 commit 32462d2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: ruby
rvm:
- 1.9
- 2.0
- 2.1
- 2.2
Expand All @@ -10,3 +9,6 @@ env:

sudo: false
cache: bundler

git:
depth: 10
1 change: 1 addition & 0 deletions lib/html/proofer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def require_all(path)
require_all 'proofer/check_runner'
require_all 'proofer/checks'
require_relative './proofer/utils'
require_relative './proofer/xpathfunctions'

require 'parallel'

Expand Down
4 changes: 2 additions & 2 deletions lib/html/proofer/checks/links.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
class LinkCheckable < ::HTML::Proofer::Checkable

def href
Expand Down Expand Up @@ -101,7 +100,8 @@ def external_link_check(link)
end

def hash_check(html, href_hash)
html.xpath("//*[@id='#{href_hash}']", "//*[@name='#{href_hash}']").length > 0
html.xpath("//*[case_insensitive_equals(@id, '#{href_hash}')]", \
"//*[case_insensitive_equals(@name, '#{href_hash}')]", HTML::Proofer::XpathFunctions.new).length > 0
end

end
9 changes: 9 additions & 0 deletions lib/html/proofer/xpathfunctions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module HTML
class Proofer
class XpathFunctions
def case_insensitive_equals(node_set, str_to_match)
node_set.find_all { |node| node.to_s.downcase == str_to_match.to_s.downcase }
end
end
end
end
3 changes: 3 additions & 0 deletions spec/html/proofer/fixtures/links/ignores_cases.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<a href="#Android">Android</a>

<h2 id="android">Android</h2>
6 changes: 6 additions & 0 deletions spec/html/proofer/links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,10 @@
proofer = run_proofer(fixture)
expect(proofer.failed_tests).to eq []
end

it 'does not complain for internal links with mismatched cases' do
fixture = "#{FIXTURES_DIR}/links/ignores_cases.html"
proofer = run_proofer(fixture)
expect(proofer.failed_tests).to eq []
end
end

0 comments on commit 32462d2

Please sign in to comment.