fix: Read trailing slash from URL, not expanded path - #877
Merged
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
unslashed_directory?tested for the trailing separator onfile, which comes fromFile.expand_path— andexpand_pathstrips 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.path), which is the only place it survives./to the site root — was reported as "internally linking to a directory without trailing slash" wheneverfollowlocationwas disabled. That was a behavior regression between 3.x and 5.x for projects that enforce trailing slashes.Fixes #848