Skip to content

Commit 59a1bf2

Browse files
committed
do not mangle path in Generic's to_s by stripping leading slashes
Leading slashes are actually valid and mean exactly the same as they would for a local path. Leading slash == absolute path, no leading slash == relative path. :/foo => actual path /foo on the remote :foo => foo relative to PWD on remote (i.e. usually ~) so, by default :foo = :/~/foo = :/home/user/foo (unless the server has a different home or PWD assigned anyway)
1 parent 12fb9d9 commit 59a1bf2

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

lib/uri/ssh_git/generic.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ class Generic < ::URI::Generic
66
# Generic.build(
77
# userinfo: 'git',
88
# host: 'github.com',
9-
# path: '/packsaddle/ruby-uri-ssh_git.git'
9+
# path: 'packsaddle/ruby-uri-ssh_git.git'
1010
# ).to_s
1111
# #=> 'git@github.com:packsaddle/ruby-uri-ssh_git.git'
1212
#
1313
# @return [String] git repository url via ssh protocol
1414
def to_s
15-
show_path = path.slice(1..-1) if path.start_with?('/')
16-
"#{user}@#{host}:#{show_path}"
15+
"#{user}@#{host}:#{path}"
1716
end
1817
end
1918
end

test/test_generic.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,30 @@ class TestGeneric < Test::Unit::TestCase
88
params = {
99
userinfo: 'git',
1010
host: 'github.com',
11-
path: '/packsaddle/ruby-uri-ssh_git.git'
11+
path: 'packsaddle/ruby-uri-ssh_git.git'
1212
}
1313
uri = 'git@github.com:packsaddle/ruby-uri-ssh_git.git'
1414
assert do
1515
Generic.build(params).to_s == uri
1616
end
1717
end
1818
end
19+
20+
sub_test_case 'leading slash' do
21+
# Leading slashes must be preserved as they denote aboslute paths
22+
# while an absence denotes relative paths.
23+
test '#to_s' do
24+
params = {
25+
userinfo: 'git',
26+
host: 'github.com',
27+
path: '/packsaddle/ruby-uri-ssh_git.git'
28+
}
29+
uri = 'git@github.com:/packsaddle/ruby-uri-ssh_git.git'
30+
assert do
31+
Generic.build(params).to_s == uri
32+
end
33+
end
34+
end
1935
end
2036
end
2137
end

0 commit comments

Comments
 (0)