lib/jekyll/url.rb passing rubocop
This commit is contained in:
parent
b5cec7d335
commit
03f7bc1a8c
|
@ -16,7 +16,6 @@ AllCops:
|
|||
- lib/jekyll/renderer.rb
|
||||
- lib/jekyll/site.rb
|
||||
- lib/jekyll/static_file.rb
|
||||
- lib/jekyll/url.rb
|
||||
- lib/jekyll/utils.rb
|
||||
- lib/jekyll.rb
|
||||
- features/step_definitions.rb
|
||||
|
|
|
@ -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