fix a bug with relative path on output_dir - #250
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f58216df2b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0b82d094a3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f6d61e79cf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| src_path = Pathname.new(src).expand_path | ||
| src_relative = src_path.relative_path_from(base_dir) | ||
| path = Pathname.new(dest).relative_path_from(src_relative.dirname) |
There was a problem hiding this comment.
Resolve relative src paths against output_dir
When output_dir is set to an absolute path and callers pass the still-supported relative src (for example relative_path_uri("a.html", ...), which is the case this change says it fixes), expanding src from the process cwd makes src_relative start with ..; the following relative_path_from(src_relative.dirname) then raises ArgumentError: base_directory has .. instead of producing the link. Relative src values should be resolved under output_dir before calculating src_relative.
Useful? React with 👍 / 👎.
Summary
Fix an error in
relative_pathwhen@param[:output_dir]is specified.Previously,
Pathname#relative_path_fromcould receive a relative src path and an absolute output_dir path, causing the following error:different prefix: "" and "/tmp/output"
This change normalizes both paths before calculating the relative path, so that path prefixes are consistent.
Types of changes
Further comments
The error occurred because
Pathname#relative_path_fromrequires both paths to use the same path prefix. When@param[:output_dir]was an absolute path butsrcwas relative, the calculation failed.The fix converts the relevant paths to absolute paths before calculating the path relative to
output_dir.