def safe_escape(uri)
      uri = uri.split('#')[0] # we want to remove the fragment if present
      uri.to_s.gsub(URI_UNSAFE) { |match|
        '%' + match.unpack('H2' * match.bytesize).join('%').upcase
      }
    end
def safe_escape(uri)
      uri = uri.split('#')[0] # we want to remove the fragment if present
      uri.to_s.gsub(URI_UNSAFE) { |match|
        '%' + match.unpack('H2' * match.bytesize).join('%').upcase
      }
    end
Internal: escapes unsafe characters from an URL which might be a path
 component only or a fully qualified URI so that it can be joined onto an
 URI:HTTP using the `+` operator. Doesn't escape "%" characters so to not
 risk double-escaping.