diff --git a/internal/addrs/module_source.go b/internal/addrs/module_source.go index 905b77e2f5c1..82000dbc4181 100644 --- a/internal/addrs/module_source.go +++ b/internal/addrs/module_source.go @@ -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 { diff --git a/internal/addrs/module_source_test.go b/internal/addrs/module_source_test.go index d6b5626ec682..1e7535ce1a9c 100644 --- a/internal/addrs/module_source_test.go +++ b/internal/addrs/module_source_test.go @@ -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://git@example.com/code/baz.git", want: ModuleSourceRemote{