-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Check symlink outside site_source without Pathutil #9015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check symlink outside site_source without Pathutil #9015
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I thought of an alternative for you to consider but your original solution is likely still best.
!Pathutil.new(entry).in_path?( | ||
site.in_source_dir | ||
) | ||
!File.realpath(entry).start_with?(site.in_source_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One alternative here might be to check if a constructed path and the real path are not equal?
site.in_source_dir(entry) != File.realpath(entry)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The downside to this is that it results in consumption of additional resources.
site.in_source_dir(entry)
is more expensive (both in terms of allocations and cpu) than site.in_source_dir
.
A better alternative to my original proposal here would be to check directly against site.source
instead:
!File.realpath(entry).start_with?(site.in_source_dir) | |
!File.realpath(entry).start_with?(site.source) |
But since EntryFilter#symlink_outside_site_source?
method is mostly invoked only if site.safe && File.symlink?(entry)
returns true
, the difference between site.source
and site.in_source_dir
is negligible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
@jekyllbot: merge +dev |
Ashwin Maroli: Check symlink outside site_source without Pathutil (#9015) Merge pull request 9015
Summary
pathutil
gem appears to be unmaintained.Therefore, emulate its existing use in
lib/jekyll/entry_filter.rb
using Ruby's built-in methods.Test Coverage
Relies on existing test defined as:
jekyll/test/test_entry_filter.rb
Lines 89 to 93 in e695c1e