Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: internal hash links #545

Merged
merged 2 commits into from Nov 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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