Merge pull request #4959 from derekgottlieb/rubocop-theme-and-url
Merge pull request 4959
This commit is contained in:
commit
986eda335c
|
@ -15,8 +15,6 @@ AllCops:
|
|||
- lib/jekyll/renderer.rb
|
||||
- lib/jekyll/site.rb
|
||||
- lib/jekyll/static_file.rb
|
||||
- lib/jekyll/theme.rb
|
||||
- lib/jekyll/url.rb
|
||||
- lib/jekyll/utils.rb
|
||||
- lib/jekyll.rb
|
||||
- bin/**/*
|
||||
|
|
|
@ -27,7 +27,7 @@ module Jekyll
|
|||
|
||||
def configure_sass
|
||||
return unless sass_path
|
||||
require 'sass'
|
||||
require "sass"
|
||||
Sass.load_paths << sass_path
|
||||
end
|
||||
|
||||
|
@ -38,7 +38,7 @@ module Jekyll
|
|||
return unless resolved_dir
|
||||
|
||||
path = Jekyll.sanitized_path(root, resolved_dir)
|
||||
path if Dir.exists?(path)
|
||||
path if File.directory?(path)
|
||||
end
|
||||
|
||||
def realpath_for(folder)
|
||||
|
@ -50,7 +50,8 @@ module Jekyll
|
|||
def gemspec
|
||||
@gemspec ||= Gem::Specification.find_by_name(name)
|
||||
rescue Gem::LoadError
|
||||
raise Jekyll::Errors::MissingDependencyException, "The #{name} theme could not be found."
|
||||
raise Jekyll::Errors::MissingDependencyException,
|
||||
"The #{name} theme could not be found."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'uri'
|
||||
require "uri"
|
||||
|
||||
# Public: Methods that generate a URL for a resource such as a Post or a Page.
|
||||
#
|
||||
|
@ -67,10 +67,10 @@ module Jekyll
|
|||
|
||||
def generate_url_from_hash(template)
|
||||
@placeholders.inject(template) do |result, token|
|
||||
break result if result.index(':').nil?
|
||||
break result if result.index(":").nil?
|
||||
if token.last.nil?
|
||||
# Remove leading '/' to avoid generating urls with `//`
|
||||
result.gsub(/\/:#{token.first}/, '')
|
||||
# Remove leading "/" to avoid generating urls with `//`
|
||||
result.gsub(%r!/:#{token.first}!, "")
|
||||
else
|
||||
result.gsub(/:#{token.first}/, self.class.escape_path(token.last))
|
||||
end
|
||||
|
@ -78,21 +78,21 @@ module Jekyll
|
|||
end
|
||||
|
||||
def generate_url_from_drop(template)
|
||||
template.gsub(/:([a-z_]+)/.freeze) do |match|
|
||||
replacement = @placeholders.public_send(match.sub(':'.freeze, ''.freeze))
|
||||
template.gsub(/:([a-z_]+)/) do |match|
|
||||
replacement = @placeholders.public_send(match.sub(":".freeze, "".freeze))
|
||||
if replacement.nil?
|
||||
''.freeze
|
||||
"".freeze
|
||||
else
|
||||
self.class.escape_path(replacement)
|
||||
end
|
||||
end.gsub(/\/\//.freeze, '/'.freeze)
|
||||
end.gsub(%r!//!, "/".freeze)
|
||||
end
|
||||
|
||||
# Returns a sanitized String URL, stripping "../../" and multiples of "/",
|
||||
# as well as the beginning "/" so we can enforce and ensure it.
|
||||
|
||||
def sanitize_url(str)
|
||||
"/" + str.gsub(/\/{2,}/, "/").gsub(/\.+\/|\A\/+/, "")
|
||||
"/" + str.gsub(%r!/{2,}!, "/").gsub(%r!\.+/|\A/+!, "")
|
||||
end
|
||||
|
||||
# Escapes a path to be a valid URL path segment
|
||||
|
@ -106,7 +106,7 @@ module Jekyll
|
|||
#
|
||||
# Returns the escaped path.
|
||||
def self.escape_path(path)
|
||||
# Because URI.escape doesn't escape '?', '[' and ']' by default,
|
||||
# Because URI.escape doesn't escape "?", "[" and "]" by default,
|
||||
# specify unsafe string (except unreserved, sub-delims, ":", "@" and "/").
|
||||
#
|
||||
# URI path segment is defined in RFC 3986 as follows:
|
||||
|
@ -116,7 +116,7 @@ module Jekyll
|
|||
# pct-encoded = "%" HEXDIG HEXDIG
|
||||
# sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
||||
# / "*" / "+" / "," / ";" / "="
|
||||
URI.escape(path, /[^a-zA-Z\d\-._~!$&'()*+,;=:@\/]/).encode('utf-8')
|
||||
URI.escape(path, %r{[^a-zA-Z\d\-._~!$&'()*+,;=:@\/]}).encode("utf-8")
|
||||
end
|
||||
|
||||
# Unescapes a URL path segment
|
||||
|
@ -130,7 +130,7 @@ module Jekyll
|
|||
#
|
||||
# Returns the unescaped path.
|
||||
def self.unescape_path(path)
|
||||
URI.unescape(path.encode('utf-8'))
|
||||
URI.unescape(path.encode("utf-8"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue