diff --git a/pkg/files/file.go b/pkg/files/file.go index accfe7cd..6a956919 100644 --- a/pkg/files/file.go +++ b/pkg/files/file.go @@ -47,6 +47,12 @@ func NewSortedFilesFromPaths(paths []string, opts SymlinkAllowOpts) ([]*File, er relativePath := "" pathPieces := strings.Split(path, "=") + if strings.HasPrefix(pathPieces[0], "http://") || strings.HasPrefix(pathPieces[0], "https://") { + pathPieces = []string{path} + } else if len(pathPieces) > 1 && (strings.HasPrefix(pathPieces[1], "http://") || strings.HasPrefix(pathPieces[1], "https://")) { + pathPieces[1] = strings.Join(pathPieces[1:], "=") + pathPieces = pathPieces[0:2] + } switch len(pathPieces) { case 1: diff --git a/pkg/files/file_test.go b/pkg/files/file_test.go new file mode 100644 index 00000000..8e05aac5 --- /dev/null +++ b/pkg/files/file_test.go @@ -0,0 +1,27 @@ +// Copyright 2024 The Carvel Authors. +// SPDX-License-Identifier: Apache-2.0 + +package files_test + +import ( + "carvel.dev/ytt/pkg/files" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "testing" +) + +func TestNewSortedFilesFromPaths(t *testing.T) { + inputPaths := []string{ + "../yamltemplate/filetests/def.tpltest", + "https://example.org/test.yaml?hello=world&foo=bar", + "an/overwritten/path/to/file.yaml=https://example.org/test.yaml?hello=world&foo=bar"} + filesToProcess, err := files.NewSortedFilesFromPaths(inputPaths, files.SymlinkAllowOpts{true, []string{}}) + + require.NoError(t, err) + + assert.Equal(t, filesToProcess[0].RelativePath(), "def.tpltest") + assert.Equal(t, filesToProcess[1].RelativePath(), "test.yaml") + assert.Equal(t, filesToProcess[1].Description(), "HTTP URL 'https://example.org/test.yaml?hello=world&foo=bar'") + assert.Equal(t, filesToProcess[2].RelativePath(), "an/overwritten/path/to/file.yaml") + assert.Equal(t, filesToProcess[2].Description(), "HTTP URL 'https://example.org/test.yaml?hello=world&foo=bar'") +} diff --git a/pkg/files/sources.go b/pkg/files/sources.go index 9c01f945..47ec54e3 100644 --- a/pkg/files/sources.go +++ b/pkg/files/sources.go @@ -97,7 +97,9 @@ func (s HTTPSource) Description() string { return fmt.Sprintf("HTTP URL '%s'", s.url) } -func (s HTTPSource) RelativePath() (string, error) { return path.Base(s.url), nil } +func (s HTTPSource) RelativePath() (string, error) { + return path.Base(strings.Split(s.url, "?")[0]), nil +} func (s HTTPSource) Bytes() ([]byte, error) { resp, err := s.Client.Get(s.url)