Skip to content

Commit

Permalink
Merge pull request #719 from gjtorikian/ugh-follow-locations-please
Browse files Browse the repository at this point in the history
Restore `follow_location`
  • Loading branch information
gjtorikian committed Jul 12, 2022
2 parents 201b673 + 73d3a86 commit 7279f37
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/html_proofer/attribute/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ def file_path
end

def unslashed_directory?(file)
File.directory?(file) && !file.end_with?(File::SEPARATOR)
return false unless File.directory?(file)

!file.end_with?(File::SEPARATOR) && !follow_location?
end

def follow_location?
@runner.options[:typhoeus] && @runner.options[:typhoeus][:followlocation]
end

def absolute_path?(path)
Expand Down
13 changes: 13 additions & 0 deletions spec/html-proofer/links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
it "finds internal hash with implict index" do
broken_hash_internal_filepath = File.join(FIXTURES_DIR, "links", "implicit_internal")
proofer = run_proofer(broken_hash_internal_filepath, :directory)
expect(proofer.failed_checks).to(eq([]))
end

it "fails to find internal hash with implict index if not asked to follow" do
options = { typhoeus: { followlocation: false } }
broken_hash_internal_filepath = File.join(FIXTURES_DIR, "links", "implicit_internal")
proofer = run_proofer(broken_hash_internal_filepath, :directory, options)
expect(proofer.failed_checks.count).to(eq(1))
expect(proofer.failed_checks.first.description).to(match(/without trailing slash/))
end
Expand Down Expand Up @@ -287,6 +294,12 @@
expect(proofer.failed_checks).to(eq([]))
end

it "allows for internal linking to a directory without trailing slash by default" do
internal = File.join(FIXTURES_DIR, "links", "link_directory_without_slash.html")
proofer = run_proofer(internal, :file)
expect(proofer.failed_checks).to(eq([]))
end

it "fails for internal linking to a directory without trailing slash" do
options = { typhoeus: { followlocation: false } }
internal = File.join(FIXTURES_DIR, "links", "link_directory_without_slash.html")
Expand Down

0 comments on commit 7279f37

Please sign in to comment.