class Addressable::URI

def normalized_path

Returns:
  • (String) - The path component, normalized.
def normalized_path
  @normalized_path ||= begin
    path = self.path.to_s
    if self.scheme == nil && path =~ NORMPATH
      # Relative paths with colons in the first segment are ambiguous.
      path = path.sub(":", "%2F")
    end
    # String#split(delimeter, -1) uses the more strict splitting behavior
    # found by default in Python.
    result = path.strip.split(SLASH, -1).map do |segment|
      Addressable::URI.normalize_component(
        segment,
        Addressable::URI::NormalizeCharacterClasses::PCHAR
      )
    end.join(SLASH)
    result = URI.normalize_path(result)
    if result.empty? &&
        ["http", "https", "ftp", "tftp"].include?(self.normalized_scheme)
      result = SLASH.dup
    end
    result
  end
  # All normalized values should be UTF-8
  force_utf8_encoding_if_needed(@normalized_path)
  @normalized_path
end