Skip to content

Commit

Permalink
resolver: always fall back to default resolver when target does not f…
Browse files Browse the repository at this point in the history
…ollow URI scheme (grpc#1889)

Previously, any target with "://" would be handled according to the URI scheme even though it did not contain a third slash.
  • Loading branch information
menghanl authored and lyuxuan committed Apr 4, 2018
1 parent fa26776 commit 7e581cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion resolver_conn_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ func parseTarget(target string) (ret resolver.Target) {
if !ok {
return resolver.Target{Endpoint: target}
}
ret.Authority, ret.Endpoint, _ = split2(ret.Endpoint, "/")
ret.Authority, ret.Endpoint, ok = split2(ret.Endpoint, "/")
if !ok {
return resolver.Target{Endpoint: target}
}
return ret
}

Expand Down
10 changes: 9 additions & 1 deletion resolver_conn_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func TestParseTargetString(t *testing.T) {
want resolver.Target
}{
{"", resolver.Target{"", "", ""}},
{"://", resolver.Target{"", "", ""}},
{":///", resolver.Target{"", "", ""}},
{"a:///", resolver.Target{"a", "", ""}},
{"://a/", resolver.Target{"", "a", ""}},
Expand All @@ -70,6 +69,15 @@ func TestParseTargetString(t *testing.T) {
{"google.com", resolver.Target{"", "", "google.com"}},
{"google.com/?a=b", resolver.Target{"", "", "google.com/?a=b"}},
{"/unix/socket/address", resolver.Target{"", "", "/unix/socket/address"}},

// If we can only parse part of the target.
{"://", resolver.Target{"", "", "://"}},
{"unix://domain", resolver.Target{"", "", "unix://domain"}},
{"a:b", resolver.Target{"", "", "a:b"}},
{"a/b", resolver.Target{"", "", "a/b"}},
{"a:/b", resolver.Target{"", "", "a:/b"}},
{"a//b", resolver.Target{"", "", "a//b"}},
{"a://b", resolver.Target{"", "", "a://b"}},
} {
got := parseTarget(test.targetStr)
if got != test.want {
Expand Down

0 comments on commit 7e581cf

Please sign in to comment.