From 73d3a864b946c09102acb3029d0e28e22c0665ef Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Mon, 11 Jul 2022 19:10:32 -0400 Subject: [PATCH] Restore `follow_location` --- lib/html_proofer/attribute/url.rb | 8 +++++++- spec/html-proofer/links_spec.rb | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/html_proofer/attribute/url.rb b/lib/html_proofer/attribute/url.rb index 8c93bc16..a7104778 100644 --- a/lib/html_proofer/attribute/url.rb +++ b/lib/html_proofer/attribute/url.rb @@ -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) diff --git a/spec/html-proofer/links_spec.rb b/spec/html-proofer/links_spec.rb index 6e538b64..acb9ad37 100644 --- a/spec/html-proofer/links_spec.rb +++ b/spec/html-proofer/links_spec.rb @@ -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 @@ -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")