Skip to content

Commit

Permalink
Merge pull request #545 from gjtorikian/fix-xpath
Browse files Browse the repository at this point in the history
Fix: internal hash links
  • Loading branch information
gjtorikian committed Nov 17, 2019
2 parents 54170f3 + 3d74c0b commit 6684adf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/html-proofer/element.rb
Expand Up @@ -150,7 +150,7 @@ def internal_absolute_link?
def relative_link?
return false if remote?

hash_link || param_link || url.start_with?('.') || url =~ /^\w/
hash_link || param_link || url.start_with?('.') || url =~ /^\S/
end

def link_points_to_same_page?
Expand Down Expand Up @@ -234,12 +234,14 @@ def base
end

def html
# If link is on the same page, then URL is on the current page so can use the same HTML as for current page
# If link is on the same page, then URL is on the current page. use the same HTML as for current page
if link_points_to_same_page?
@html
elsif relative_link?
elsif internal?
# link on another page, e.g. /about#Team - need to get HTML from the other page
create_nokogiri(absolute_path)
else
raise NotImplementedError, 'HTMLProofer should not have gotten here. Please report this as a bug.'
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions spec/html-proofer/fixtures/links/relative_hash.html
@@ -0,0 +1,3 @@
<ul class="dropdown-menu">
<li><a href="/broken_link_internal.html#safeHash">Forums</a></li>
</ul>
6 changes: 6 additions & 0 deletions spec/html-proofer/links_spec.rb
Expand Up @@ -134,6 +134,12 @@
expect(proofer.failed_tests.first).to match(/linking to internal hash #25-method-not-allowed that does not exist/)
end

it 'should understand relative hash' do
link_with_https_filepath = "#{FIXTURES_DIR}/links/relative_hash.html"
proofer = run_proofer(link_with_https_filepath, :file)
expect(proofer.failed_tests).to eq []
end

it 'properly resolves implicit /index.html in link paths' do
link_to_folder = "#{FIXTURES_DIR}/links/link_to_folder.html"
proofer = run_proofer(link_to_folder, :file)
Expand Down

0 comments on commit 6684adf

Please sign in to comment.