Force encoding before escaping or unescaping

This will reassure not having any errors when escaping or
unescaping.
This commit is contained in:
Alberto Grespan 2014-05-19 18:50:25 -04:30
parent 2f3390750d
commit 77cef764d6
1 changed files with 2 additions and 2 deletions

View File

@ -89,7 +89,7 @@ module Jekyll
# pct-encoded = "%" HEXDIG HEXDIG # pct-encoded = "%" HEXDIG HEXDIG
# sub-delims = "!" / "$" / "&" / "'" / "(" / ")" # sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
# / "*" / "+" / "," / ";" / "=" # / "*" / "+" / "," / ";" / "="
URI.escape(path, /[^a-zA-Z\d\-._~!$&\'()*+,;=:@\/]/).encode('utf-8') URI.escape(path.force_encoding('utf-8'), /[^a-zA-Z\d\-._~!$&\'()*+,;=:@\/]/).encode('utf-8')
end end
# Unescapes a URL path segment # Unescapes a URL path segment
@ -103,7 +103,7 @@ module Jekyll
# #
# Returns the unescaped path. # Returns the unescaped path.
def self.unescape_path(path) def self.unescape_path(path)
URI.unescape(path.encode('utf-8')) URI.unescape(path.force_encoding('utf-8'))
end end
end end
end end