Skip to content

Commit

Permalink
ModuleSourceRemote String now considers presence of query string (has…
Browse files Browse the repository at this point in the history
  • Loading branch information
fatahfattah committed Aug 25, 2022
1 parent 2aff678 commit d98f4a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/addrs/module_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,17 @@ func parseModuleSourceRemote(raw string) (ModuleSourceRemote, error) {
func (s ModuleSourceRemote) moduleSource() {}

func (s ModuleSourceRemote) String() string {
base := s.Package.String()

if s.Subdir != "" {
return s.Package.String() + "//" + s.Subdir
// Address contains query string
if strings.Contains(base, "?") {
parts := strings.SplitN(base, "?", 2)
return parts[0] + "//" + s.Subdir + "?" + parts[1]
}
return base + "//" + s.Subdir
}
return s.Package.String()
return base
}

func (s ModuleSourceRemote) ForDisplay() string {
Expand Down
7 changes: 7 additions & 0 deletions internal/addrs/module_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ func TestParseModuleSource(t *testing.T) {
Subdir: "bleep/bloop",
},
},
"git over HTTPS, URL-style, subdir, query parameters": {
input: "git::https://example.com/code/baz.git//bleep/bloop?otherthing=blah",
want: ModuleSourceRemote{
Package: ModulePackage("git::https://example.com/code/baz.git?otherthing=blah"),
Subdir: "bleep/bloop",
},
},
"git over SSH, URL-style": {
input: "git::ssh://[email protected]/code/baz.git",
want: ModuleSourceRemote{
Expand Down

0 comments on commit d98f4a6

Please sign in to comment.