Method: Addressable::URI#normalized_path

Defined in:
lib/vendor/addressable/lib/addressable/uri.rb

#normalized_pathString

The path component for this URI, normalized.

Returns:

  • (String)

    The path component, normalized.



1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
# File 'lib/vendor/addressable/lib/addressable/uri.rb', line 1108

def normalized_path
  @normalized_path ||= (begin
    if self.scheme == nil && self.path != nil && self.path != "" &&
        self.path =~ /^(?!\/)[^\/:]*:.*$/
      # Relative paths with colons in the first segment are ambiguous.
      self.path.sub!(":", "%2F")
    end
    # String#split(delimeter, -1) uses the more strict splitting behavior
    # found by default in Python.
    result = (self.path.strip.split("/", -1).map do |segment|
      Addressable::URI.normalize_component(
        segment,
        Addressable::URI::CharacterClasses::PCHAR
      )
    end).join("/")
    result = self.class.normalize_path(result)
    if result == "" &&
        ["http", "https", "ftp", "tftp"].include?(self.normalized_scheme)
      result = "/"
    end
    result
  end)
end