class Addressable::URI

def self.normalize_path(path)

def self.normalize_path(path)
  # Section 5.2.4 of RFC 3986
  return nil if path.nil?
  normalized_path = path.dup
  begin
    mod = nil
    mod ||= normalized_path.gsub!(NPATH1, SLASH)
    parent = normalized_path.match(NPATH2)
    if parent && ((parent[1] != PARENT1 && parent[1] != PARENT2) \
                  || (parent[2] != PARENT1 && parent[2] != PARENT2))
      mod ||= normalized_path.gsub!(/\/#{parent[1]}\/\.\.\/|(\/#{parent[2]}\/\.\.$)/, SLASH)
    end
    mod ||= normalized_path.gsub!(NPATH3, EMPTYSTR)
    mod ||= normalized_path.gsub!(NPATH4, SLASH)
  end until mod.nil?
  return normalized_path
end