Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

sanitize urls and ignore symlinks

  • Loading branch information...
commit 13cc44fb1257ab60f433f7ae689f4cd770709ea3 1 parent be8b771
@tmm1 tmm1 authored
Showing with 45 additions and 24 deletions.
  1. +17 −8 lib/jekyll/page.rb
  2. +23 −14 lib/jekyll/post.rb
  3. +5 −2 lib/jekyll/site.rb
View
25 lib/jekyll/page.rb
@@ -55,14 +55,23 @@ def template
#
# Returns <String>
def url
- return permalink if permalink
-
- @url ||= {
- "basename" => self.basename,
- "output_ext" => self.output_ext,
- }.inject(template) { |result, token|
- result.gsub(/:#{token.first}/, token.last)
- }.gsub(/\/\//, "/")
+ return @url if @url
+
+ url = if permalink
+ permalink
+ else
+ {
+ "basename" => self.basename,
+ "output_ext" => self.output_ext,
+ }.inject(template) { |result, token|
+ result.gsub(/:#{token.first}/, token.last)
+ }.gsub(/\/\//, "/")
+ end
+
+ # sanitize url
+ @url = url.split('/').reject{ |part| part =~ /^\.+$/ }.join('/')
+ @url += "/" if url =~ /\/$/
+ @url
end
# Extract information from the page filename
View
37 lib/jekyll/post.rb
@@ -117,20 +117,29 @@ def template
#
# Returns <String>
def url
- return permalink if permalink
-
- @url ||= {
- "year" => date.strftime("%Y"),
- "month" => date.strftime("%m"),
- "day" => date.strftime("%d"),
- "title" => CGI.escape(slug),
- "i_day" => date.strftime("%d").to_i.to_s,
- "i_month" => date.strftime("%m").to_i.to_s,
- "categories" => categories.join('/'),
- "output_ext" => self.output_ext
- }.inject(template) { |result, token|
- result.gsub(/:#{Regexp.escape token.first}/, token.last)
- }.gsub(/\/\//, "/")
+ return @url if @url
+
+ url = if permalink
+ permalink
+ else
+ {
+ "year" => date.strftime("%Y"),
+ "month" => date.strftime("%m"),
+ "day" => date.strftime("%d"),
+ "title" => CGI.escape(slug),
+ "i_day" => date.strftime("%d").to_i.to_s,
+ "i_month" => date.strftime("%m").to_i.to_s,
+ "categories" => categories.join('/'),
+ "output_ext" => self.output_ext
+ }.inject(template) { |result, token|
+ result.gsub(/:#{Regexp.escape token.first}/, token.last)
+ }.gsub(/\/\//, "/")
+ end
+
+ # sanitize url
+ @url = url.split('/').reject{ |part| part =~ /^\.+$/ }.join('/')
+ @url += "/" if url =~ /\/$/
+ @url
end
# The UID for this post (useful in feeds)
View
7 lib/jekyll/site.rb
@@ -210,7 +210,7 @@ def write
# Returns nothing
def read_directories(dir = '')
base = File.join(self.source, dir)
- entries = filter_entries(Dir.entries(base))
+ entries = Dir.chdir(base){ filter_entries(Dir['*']) }
self.read_posts(dir)
@@ -268,7 +268,10 @@ def site_payload
def filter_entries(entries)
entries = entries.reject do |e|
unless ['.htaccess'].include?(e)
- ['.', '_', '#'].include?(e[0..0]) || e[-1..-1] == '~' || self.exclude.include?(e)
+ ['.', '_', '#'].include?(e[0..0]) ||
+ e[-1..-1] == '~' ||
+ self.exclude.include?(e) ||
+ File.symlink?(e)
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.