summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorakira <akira@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-10-04 06:26:45 +0000
committerakira <akira@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-10-04 06:26:45 +0000
commit05e476c941e41132d40b4bcbfcc7eea90cae7318 (patch)
treeabe5147994e8566c8c4f7f49e59378f9683df2d3 /lib
parent396c29d1952642868874cace40615c2f1aae153b (diff)
updated uri.rb and uri/*.rb to uri-0.9.7
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2934 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/uri.rb2
-rw-r--r--lib/uri/common.rb44
-rw-r--r--lib/uri/generic.rb45
-rw-r--r--lib/uri/ldap.rb5
-rw-r--r--lib/uri/mailto.rb17
5 files changed, 76 insertions, 37 deletions
diff --git a/lib/uri.rb b/lib/uri.rb
index beb1443697..568ff008c7 100644
--- a/lib/uri.rb
+++ b/lib/uri.rb
@@ -15,7 +15,7 @@
=end
module URI
- VERSION_CODE = '000907'.freeze
+ VERSION_CODE = '000908'.freeze
VERSION = VERSION_CODE.scan(/../).collect{|n| n.to_i}.join('.').freeze
end
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index ea7d3c8865..aabb887db2 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -151,8 +151,10 @@ module URI
(?:(#{PATTERN::HOST})(?::(\\d*))?))?(?# 3: host, 4: port)
|
(#{PATTERN::REG_NAME}) (?# 5: registry)
- ))?
- ((?!//)#{PATTERN::ABS_PATH})? (?# 6: path)
+ )
+ |
+ (?!//)) (?# XXX: '//' is the mark for hostport)
+ (#{PATTERN::ABS_PATH})? (?# 6: path)
)(?:\\?(#{PATTERN::QUERY}))? (?# 7: query)
|
(#{PATTERN::OPAQUE_PART}) (?# 8: opaque)
@@ -396,32 +398,22 @@ module URI
=end
def self.extract(str, schemes = [])
urls = []
- if schemes.size > 0
- tmp = Regexp.new('(?:' + schemes.collect{|s|
- Regexp.quote(s + ':')
- }.join('|') + ')',
- Regexp::IGNORECASE, 'N')
- str.scan(tmp) {
- tmp_str = $& + $'
- if ABS_URI_REF =~ tmp_str
- if block_given?
- yield($&)
- else
- urls << $&
- end
- end
- }
-
- else
- str.scan(ABS_URI_REF) {
- if block_given?
- yield($&)
- else
- urls << $&
- end
- }
+ regexp = ABS_URI_REF
+ unless schemes.empty?
+ regexp = Regexp.new('(?=' + schemes.collect{|s|
+ Regexp.quote(s + ':')
+ }.join('|') + ')' + PATTERN::X_ABS_URI,
+ Regexp::IGNORECASE, 'N')
end
+ str.scan(ABS_URI_REF) {
+ if block_given?
+ yield($&)
+ else
+ urls << $&
+ end
+ }
+
if block_given?
return nil
else
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index 5071c1af93..73f80c946c 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -183,6 +183,18 @@ Object
attr_reader :opaque
attr_reader :fragment
+ # replace self by other URI object
+ def replace!(oth)
+ if self.class != oth.class
+ raise ArgumentError, "expected #{self.class} object"
+ end
+
+ component.each do |c|
+ self.__send__("#{c}=", oth.__send__(c))
+ end
+ end
+ private :replace!
+
=begin
=== Instance Methods
@@ -436,7 +448,13 @@ Object
private :check_port
def set_port(v)
- v = v.to_i if v && !v.kind_of?(Fixnum)
+ unless !v || v.kind_of?(Fixnum)
+ if v.empty?
+ v = nil
+ else
+ v = v.to_i
+ end
+ end
@port = v
end
protected :set_port
@@ -683,6 +701,7 @@ Object
=begin
--- URI::Generic#merge(rel)
+--- URI::Generic#merge!(rel)
--- URI::Generic#+(rel)
=end
@@ -750,6 +769,16 @@ Object
end
private :merge_path
+ def merge!(oth)
+ t = merge(oth)
+ if self == t
+ nil
+ else
+ replace!(t)
+ self
+ end
+ end
+
# abs(self) + rel(oth) => abs(new)
def merge(oth)
base, rel = merge0(oth)
@@ -1085,6 +1114,20 @@ Object
end
=begin
+--- URI::Generic#select(*components)
+=end
+ def select(*components)
+ components.collect do |c|
+ if component.include?(c)
+ self.send(c)
+ else
+ raise ArgumentError,
+ "expected of components of #{self.class} (#{self.class.component.join(', ')})"
+ end
+ end
+ end
+
+=begin
=end
def inspect
sprintf("#<%s:0x%x URL:%s>", self.class.to_s, self.id, self.to_s)
diff --git a/lib/uri/ldap.rb b/lib/uri/ldap.rb
index 441ee69b86..2911aa5738 100644
--- a/lib/uri/ldap.rb
+++ b/lib/uri/ldap.rb
@@ -134,6 +134,7 @@ URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
def set_dn(val)
@dn = val
build_path_query
+ @dn
end
protected :set_dn
@@ -156,6 +157,7 @@ URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
def set_attributes(val)
@attributes = val
build_path_query
+ @attributes
end
protected :set_attributes
@@ -178,6 +180,7 @@ URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
def set_scope(val)
@scope = val
build_path_query
+ @scope
end
protected :set_scope
@@ -200,6 +203,7 @@ URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
def set_filter(val)
@filter = val
build_path_query
+ @filter
end
protected :set_filter
@@ -222,6 +226,7 @@ URI::LDAP is copyrighted free software by Takaaki Tateishi and akira yamada.
def set_extensions(val)
@extensions = val
build_path_query
+ @extensions
end
protected :set_extensions
diff --git a/lib/uri/mailto.rb b/lib/uri/mailto.rb
index b1c18f4364..100cd6430b 100644
--- a/lib/uri/mailto.rb
+++ b/lib/uri/mailto.rb
@@ -46,22 +46,21 @@ module URI
# hname = *urlc
# hvalue = *urlc
# header = hname "=" hvalue
- header_pattern = "(?:[^?=&]*=[^?=&]*)"
- HEADER_REGEXP = /#{header_pattern}/
+ HEADER_PATTERN = "(?:[^?=&]*=[^?=&]*)".freeze
+ HEADER_REGEXP = Regexp.new(HEADER_PATTERN, 'N').freeze
# headers = "?" header *( "&" header )
# to = #mailbox
# mailtoURL = "mailto:" [ to ] [ headers ]
- mailbox_pattern = "(?:[^(),%?=&]|#{PATTERN::ESCAPED})"
- MAILBOX_REGEXP = /#{mailbox_pattern}/
+ MAILBOX_PATTERN = "(?:[^(),%?=&]|#{PATTERN::ESCAPED})".freeze
MAILTO_REGEXP = Regexp.new("
\\A
- (#{mailbox_pattern}*?) (?# 1: to)
+ (#{MAILBOX_PATTERN}*?) (?# 1: to)
(?:
\\?
- (#{header_pattern}(?:\\&#{header_pattern})*) (?# 2: headers)
+ (#{HEADER_PATTERN}(?:\\&#{HEADER_PATTERN})*) (?# 2: headers)
)?
\\z
- ", Regexp::EXTENDED, 'N')
+ ", Regexp::EXTENDED, 'N').freeze
=begin
@@ -155,7 +154,7 @@ module URI
return true unless v
return true if v.size == 0
- if OPAQUE !~ v || /\A#{MAILBOX_REGEXP}*\z/o !~ v
+ if OPAQUE !~ v || /\A#{MAILBOX_PATTERN}*\z/o !~ v
raise InvalidComponentError,
"bad component(expected opaque component): #{v}"
end
@@ -191,7 +190,7 @@ module URI
return true if v.size == 0
if OPAQUE !~ v ||
- /\A(#{HEADER_REGEXP}(?:\&#{HEADER_REGEXP})*)\z/o !~ v
+ /\A(#{HEADER_PATTERN}(?:\&#{HEADER_PATTERN})*)\z/o !~ v
raise InvalidComponentError,
"bad component(expected opaque component): #{v}"
end