Check symlink outside site_source without Pathutil#9015
Check symlink outside site_source without Pathutil#9015jekyllbot merged 1 commit intojekyll:masterfrom
Conversation
parkr
left a comment
There was a problem hiding this comment.
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.
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.
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.
|
@jekyllbot: merge +dev |
Ashwin Maroli: Check symlink outside site_source without Pathutil (#9015) Merge pull request 9015
Summary
pathutilgem appears to be unmaintained.Therefore, emulate its existing use in
lib/jekyll/entry_filter.rbusing 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