Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/uri/ftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,20 @@ def set_path(v)
end
protected :set_path

# An empty FTP path is the login directory. Generic#normalize! would
# pass "/" through set_path, which encodes it as the root (%2F).
def normalize!
if path&.empty?
@path = '/'
end
if scheme && scheme != scheme.downcase
set_scheme(scheme.downcase)
end
if host && host != host.downcase
set_host(host.downcase)
end
end

# Returns a String representation of the URI::FTP.
def to_s
save_path = nil
Expand Down
7 changes: 7 additions & 0 deletions test/uri/test_ftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def test_assemble
uri.to_s)
end

def test_normalize_empty_path
assert_equal('ftp://ftp.example.com/', URI.parse('ftp://ftp.example.com').normalize.to_s)
assert_equal('ftp://ftp.example.com/', URI.parse('FTP://FTP.Example.COM').normalize.to_s)
assert_equal('ftp://ftp.example.com/pub', URI.parse('ftp://ftp.example.com/pub').normalize.to_s)
assert_equal('ftp://ftp.example.com/%2Fpub', URI.parse('ftp://ftp.example.com/%2Fpub').normalize.to_s)
end

def test_select
assert_equal(['ftp', 'a.b.c', 21], URI.parse('ftp://a.b.c/').select(:scheme, :host, :port))
u = URI.parse('ftp://a.b.c/')
Expand Down