Unexpected behavior with internal trailing slashes if not following redirects
In upgrading from 3.x to 5.x, we've noticed a change in behavior with how `followlocation` affects internal link checking with trailing slashes.
Specifically, we want to enforce that internal links have trailing slashes, but `html-proofer` produces errors even if they do have trailing slashes.
It seems to be enforcing the _absence_ of a trailing slash, despite the error message indicating that it lacks one.
I was able to imitate what we're expecting with a failing spec as a proof of concept:
```diff
diff --git a/spec/html-proofer/check/links_spec.rb b/spec/html-proofer/check/links_spec.rb
index f50154b..4a054c6 100644
--- a/spec/html-proofer/check/links_spec.rb
+++ b/spec/html-proofer/check/links_spec.rb
@@ -326,2 +326,9 @@ describe "Check::Links" do
+ it "allows for internal linking to a directory with trailing slash when not following" do
+ options = { typhoeus: { followlocation: false } }
+ internal = File.join(FIXTURES_DIR, "links", "link_to_folder.html")
+ proofer = run_proofer(internal, :file, options)
+ expect(proofer.failed_checks).to(eq([]))
+ end
+
it "fails for internal linking to a directory without trailing slash" do
```
Example error in our project:
```
* At /Code/_site/index.html:203:
internally linking to a directory / without trailing slash
```
Corresponding markup in `index.html`:
```html
<a href="/" lang="en" hreflang="en">
English
</a>
```
The behavior seems to stem from `File.expand_path` in `HTMLProofer::Attribute::Url#absolute_path`, which strips the trailing slash:
https://github.com/gjtorikian/html-proofer/blob/590336026ee84e7a416a5e1ea80ff2e925fc91db/lib/html_proofer/attribute/url.rb#L151-L155
```rb
File.expand_path('/Code/_site/', '/Code/_site/')
# "/Code/_site"
```
Since `absolute_path` is used as the `unslashed_directory?` argument, the unslashing produces a failure.
https://github.com/gjtorikian/html-proofer/blob/590336026ee84e7a416a5e1ea80ff2e925fc91db/lib/html_proofer/check/links.rb#L59
1 条评论