summaryrefslogtreecommitdiff
path: root/lib/uri
diff options
context:
space:
mode:
Diffstat (limited to 'lib/uri')
-rw-r--r--lib/uri/ftp.rb8
-rw-r--r--lib/uri/generic.rb4
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/uri/ftp.rb b/lib/uri/ftp.rb
index 1ffd9090a6..4e33dadd33 100644
--- a/lib/uri/ftp.rb
+++ b/lib/uri/ftp.rb
@@ -118,12 +118,13 @@ module URI
# +opaque+, +query+ and +fragment+, in that order.
#
def initialize(*arg)
+ arg[5] = arg[5].sub(/^\//,'').sub(/^%2F/,'/')
super(*arg)
@typecode = nil
tmp = @path.index(TYPECODE_PREFIX)
if tmp
typecode = @path[tmp + TYPECODE_PREFIX.size..-1]
- self.set_path(@path[0..tmp - 1])
+ @path = @path[0..tmp - 1]
if arg[-1]
self.typecode = typecode
@@ -185,6 +186,11 @@ module URI
return @path.sub(/^\//,'').sub(/^%2F/,'/')
end
+ def set_path(v)
+ super("/" + v.sub(/^\//, "%2F"))
+ end
+ protected :set_path
+
def to_s
save_path = nil
if @typecode
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index 14ca97301b..4fdfd140fe 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -482,7 +482,9 @@ module URI
"path conflicts with opaque"
end
- if @scheme
+ # If scheme is ftp, path may be relative.
+ # See RFC 1738 section 3.2.2, and RFC 2396.
+ if @scheme && @scheme != "ftp"
if v && v != '' && parser.regexp[:ABS_PATH] !~ v
raise InvalidComponentError,
"bad component(expected absolute path component): #{v}"