Encode and unencode urls only as required (#7654)
Merge pull request 7654
This commit is contained in:
parent
8c5ee73661
commit
20c9d0957a
|
@ -129,6 +129,8 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the escaped path.
|
# Returns the escaped path.
|
||||||
def self.escape_path(path)
|
def self.escape_path(path)
|
||||||
|
return path if path.empty? || %r!^[a-zA-Z0-9./-]+$!.match?(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 "/").
|
# specify unsafe string (except unreserved, sub-delims, ":", "@" and "/").
|
||||||
#
|
#
|
||||||
|
@ -139,8 +141,7 @@ module Jekyll
|
||||||
# pct-encoded = "%" HEXDIG HEXDIG
|
# pct-encoded = "%" HEXDIG HEXDIG
|
||||||
# sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
# sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
||||||
# / "*" / "+" / "," / ";" / "="
|
# / "*" / "+" / "," / ";" / "="
|
||||||
path = Addressable::URI.encode(path)
|
Addressable::URI.encode(path).encode("utf-8").sub("#", "%23")
|
||||||
path.encode("utf-8").sub("#", "%23")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Unescapes a URL path segment
|
# Unescapes a URL path segment
|
||||||
|
@ -154,7 +155,10 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns the unescaped path.
|
# Returns the unescaped path.
|
||||||
def self.unescape_path(path)
|
def self.unescape_path(path)
|
||||||
Addressable::URI.unencode(path.encode("utf-8"))
|
path = path.encode("utf-8")
|
||||||
|
return path unless path.include?("%")
|
||||||
|
|
||||||
|
Addressable::URI.unencode(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue