Question: Why rack-jekyll finds file from long string?
sorah opened this issue · 5 comments
https://github.com/adaoraul/rack-jekyll/blob/master/lib/rack/jekyll.rb#L69-L70
@files.include?(path_info)
seems to be for find proper file to render. but, @files
is a String generated by Array#inspect
.
Using String#include?
leads to match partial path.
path_info = "/b"
p ["_site/a/b/c"].inspect.include?(path_info) #=> true
p ["_site/a/b/c"].include?(path_info) #=> false
so in this case, when user requested to /b
that doesn't exist, rack-jekyll returns error like the following
No such file or directory @ rb_sysopen - www.ruby-lang.org/_site/b/index.html
App 9033 stderr: from rack-jekyll-0.4.1/lib/rack/jekyll/helpers.rb:14:in `initialize'
App 9033 stderr: from rack-jekyll-0.4.1/lib/rack/jekyll/helpers.rb:14:in `open'
App 9033 stderr: from rack-jekyll-0.4.1/lib/rack/jekyll/helpers.rb:14:in `file_info'
App 9033 stderr: from rack-jekyll-0.4.1/lib/rack/jekyll.rb:77:in `call'
App 9033 stderr: from rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
App 9033 stderr: from rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
App 9033 stderr: from rack-rewrite-1.5.0/lib/rack/rewrite.rb:24:in `call'
App 9033 stderr: from rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
I guess this is bug... but I guess there's some reason to use inspect
maybe, so I'm asking question before pull-request.
Thoughts?
@sorah ["_site/a/b/c"].include?(path_info)
is search over Array
to metch with ==
, but to select to Regexp use #grep
as follows ["_site/a/b/c"].grep(/#{path_info}/).any?
using grep
doesn't solve the problem, still matches partial path
path_info = "/b"
p ["_site/a/b/c"].grep(/#{Regexp.escape(path_info)}/) #=> true
This solves my problem:
# assuming @path == "_site"
p ["_site/a/b/c"].include?(File.join(@path, path_info)) #=> true
that still matches partially and causes the problem; rack-jekyll will see _site/b/index.html
and raises an error