module Protocol::HTTP::URL
def self.escape_path(path)
@parameter path [String] The path to escape.
Escapes non-path characters using percent encoding. In other words, this method escapes characters that are not allowed in a URI path segment. According to RFC 3986 Section 3.3 (https://tools.ietf.org/html/rfc3986#section-3.3), a valid path segment consists of "pchar" characters. This method percent-encodes characters that are not "pchar" characters.
def self.escape_path(path) encoding = path.encoding path.b.gsub(NON_PATH_CHARACTER_PATTERN) do |m| "%" + m.unpack("H2" * m.bytesize).join("%").upcase end.force_encoding(encoding) end