Skip to content

fix: Read trailing slash from URL, not expanded path - #877

Merged
gjtorikian merged 6 commits into
mainfrom
trailing-slash-expand-path
Jul 28, 2026
Merged

fix: Read trailing slash from URL, not expanded path#877
gjtorikian merged 6 commits into
mainfrom
trailing-slash-expand-path

Conversation

@gjtorikian

Copy link
Copy Markdown
Owner

Summary

  • unslashed_directory? tested for the trailing separator on file, which comes from File.expand_path — and expand_path strips trailing separators. The slash could therefore never be observed there, so the check effectively enforced the absence of a trailing slash while reporting the opposite.
  • The slash is now read off the URL as written (path), which is the only place it survives.
  • Consequence for users: any directory link written with a trailing slash — including a bare / to the site root — was reported as "internally linking to a directory without trailing slash" whenever followlocation was disabled. That was a behavior regression between 3.x and 5.x for projects that enforce trailing slashes.

Fixes #848

gjtorikian and others added 6 commits July 28, 2026 12:25
`File.expand_path` strips trailing separators, so the slash could
never be observed on the resolved filesystem path. Any directory
link written with a trailing slash — including a bare `/` to the
site root — was therefore reported as missing one whenever
`followlocation` was disabled.
Typhoeus exposes response headers via :response_headers and only
populates :headers on stubbed responses, so this lookup matched
nothing outside VCR playback. PDF links carrying a #page=N hash
therefore skipped the page check on every real run, fell through to
HTML parsing of the raw PDF bytes, and reported the hash as missing.
The hash check re-reads PDF responses with OpenURI, which VCR does
not intercept, so this spec reached upload.wikimedia.org on every
run and CI failed whenever that host rate-limited it. Serving a
460-byte fixture over loopback removes the last unrecorded network
dependency in the suite.

Built on TCPServer rather than webrick, which left stdlib in Ruby
3.0 and would otherwise mean a new development dependency to serve
a single file.
@gjtorikian
gjtorikian merged commit 5715743 into main Jul 28, 2026
3 checks passed
@gjtorikian
gjtorikian deleted the trailing-slash-expand-path branch July 28, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected behavior with internal trailing slashes if not following redirects

1 participant