Sha256: 5a67bc2f7ecf78a13abdb394e7d7463d5f06576afebf67e89c8140b22915b409
Contents?: true
Size: 854 Bytes
Versions: 8
Compression:
Stored size: 854 Bytes
Contents
require 'uri' module URI # # Expands a URI decoded path, into a proper absolute path. # # @param [String] path # The path from a URI. # # @return [String] # The expanded path. # # @example # URI.expand_path('./path') # # => "path" # # @example # URI.expand_path('test/../path') # # => "path" # # @example # URI.exand_path('/test/path/') # # => "/test/path/" # # @example # URI.expand_path('/test/../path') # # => "/path" # def URI.expand_path(path) dirs = path.gsub(/[\/]{2,}/,'/').scan(/[^\/]*\/|[^\/]+$/) new_dirs = [] dirs.each do |dir| if (dir == '..' || dir == '../') unless new_dirs == ['/'] new_dirs.pop end elsif (dir != '.' && dir != './') new_dirs.push(dir) end end return new_dirs.join end end
Version data entries
8 entries across 8 versions & 1 rubygems