Skip to content

Commit

Permalink
sanitize urls and ignore symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Mar 11, 2011
1 parent be8b771 commit 13cc44f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
25 changes: 17 additions & 8 deletions lib/jekyll/page.rb
Expand Up @@ -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
Expand Down
37 changes: 23 additions & 14 deletions lib/jekyll/post.rb
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions lib/jekyll/site.rb
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 13cc44f

Please sign in to comment.