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

Restore follow_location #719

Merged
merged 1 commit into from
Jul 12, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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