diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-11-13 11:39:16 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-11-13 11:39:16 +0000 |
commit | e008c87423eb369afb4a189ac0b700c8920b7fa6 (patch) | |
tree | a98ddcad1e3c24f978235802e2d9e3574184e81d | |
parent | 00c9f4cb9ba306d6aac1635e0b7d099e80633ab1 (diff) |
* lib/open-uri.rb (Kernel[#.]open): hard coded URI schemes removed.
[ruby-ext:02251]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/open-uri.rb | 27 |
2 files changed, 25 insertions, 8 deletions
@@ -1,3 +1,8 @@ +Thu Nov 13 20:34:17 2003 Tanaka Akira <akr@m17n.org> + + * lib/open-uri.rb (Kernel[#.]open): hard coded URI schemes removed. + [ruby-ext:02251] + Thu Nov 13 19:17:00 2003 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> * lib/test/unit/ui/tk/testrunner.rb: use grid and panedwindow @@ -7,6 +12,7 @@ Thu Nov 13 17:56:41 2003 Tanaka Akira <akr@m17n.org> * lib/open-uri.rb (OpenURI.open_uri): use File::RDONLY. reported by Take_tk <ggb03124@nifty.ne.jp>. + [ruby-ext:02245] Thu Nov 13 16:45:53 2003 GOTOU Yuuzou <gotoyuzo@notwork.org> diff --git a/lib/open-uri.rb b/lib/open-uri.rb index 132a1f4662..d01496ce71 100644 --- a/lib/open-uri.rb +++ b/lib/open-uri.rb @@ -62,16 +62,27 @@ module Kernel private alias open_uri_original_open open # :nodoc: - # makes possible to open URIs. - # If the first argument is URI::HTTP, URI::FTP or - # String beginning with http:// or ftp://, - # the URI is opened. - # The opened file object is extended by OpenURI::Meta. + # makes possible to open various resources including URIs. + # If the first argument respond to `open' method, + # the method is called with the rest arguments. + # + # If the first argument is a string and begins with xxx://, + # it is parsed by URI.parse. If the parsed object respond to `open' method, + # the method is called with the rest arguments. + # + # Otherwise original open is called. + # + # Since open-uri.rb provides URI::HTTP#open and URI::FTP#open, + # Kernel[#.]open can accepts such URIs and strings which begins with + # http:// and ftp://. In this http and ftp case, the opened file object + # is extended by OpenURI::Meta. def open(name, *rest, &block) if name.respond_to?("open") name.open(*rest, &block) - elsif name.respond_to?("to_str") && %r{\A(http|ftp)://} =~ name - OpenURI.open_uri(name, *rest, &block) + elsif name.respond_to?("to_str") && + %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name && + (uri = URI.parse(name)).respond_to?(:open) + uri.open(*rest, &block) else open_uri_original_open(name, *rest, &block) end @@ -307,7 +318,7 @@ module OpenURI end end - # Mixin for URIs. + # Mixin for HTTP and FTP URIs. module OpenRead # opens the URI. def open(*rest, &block) |