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
9 changes: 3 additions & 6 deletions lib/uri/ftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,11 @@ def set_path(v)

# Returns a String representation of the URI::FTP.
def to_s
save_path = nil
if @typecode
save_path = @path
@path = @path + TYPECODE_PREFIX + @typecode
end
str = super
if @typecode
@path = save_path
suffix_length = (@query ? @query.length + 1 : 0) +
(@fragment ? @fragment.length + 1 : 0)
str.insert(-suffix_length - 1, TYPECODE_PREFIX + @typecode)
end

return str
Expand Down
9 changes: 9 additions & 0 deletions test/uri/test_ftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ class URI::TestFTP < Test::Unit::TestCase
def setup
end


def test_to_s_does_not_mutate_frozen_ftp_uri
uri = URI.parse("ftp://example.test/file;type=i?download=1#section").freeze

2.times do
assert_equal("ftp://example.test/file;type=i?download=1#section", uri.to_s)
end
end

def test_parse
url = URI.parse('ftp://user:pass@host.com/abc/def')
assert_kind_of(URI::FTP, url)
Expand Down