public Method

HTTPUtils.normalize_path(path)

There's no documentation for this item.

Source Code

# File webrick/httputils.rb, line 21
def normalize_path(path)
  raise "abnormal path `#{path}'" if path[0] != ?/
  ret = path.dup

  ret.gsub!(%r{/+}o, '/')                    # //      => /
  while ret.sub!(%r{/\.(/|\Z)}o, '/'); end   # /.      => /
  begin                                      # /foo/.. => /foo
    match = ret.sub!(%r{/([^/]+)/\.\.(/|\Z)}o){
      if $1 == ".."
        raise "abnormal path `#{path}'"
      else
        "/"
      end
    }
  end while match

  raise "abnormal path `#{path}'" if %r{/\.\.(/|\Z)} =~ ret
  ret
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.