Skip to content

Commit

Permalink
Automatically lower case uris. (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch authored Sep 13, 2023
1 parent 1d2572f commit 85991d7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/tpkg/desc.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ func (d *Desc) Parse(b []byte, ui UI) error {
return fail(err)
}

// Force the URL to be lower-case.
// This avoids issues with case-insensitive file systems, and with
// projects that have been registered with different casing.
if !strings.HasPrefix(d.URL, TestGitPathHost) {
d.URL = strings.ToLower(d.URL)
}

if err := d.Validate(ui); err != nil {
return fail(err)
}
Expand Down Expand Up @@ -394,7 +401,15 @@ func ScrapeDescriptionGit(ctx context.Context, url string, v string, allowsLocal
// We thus add another segment to the directory path.
dir := filepath.Join(tmpDir, "pkg")

// Force the url to be lower-case.
// This avoids issues with case-insensitive file systems, and with
// projects that have been registered with different casing.
if !strings.HasPrefix(url, TestGitPathHost) {
url = strings.ToLower(url)
}

httpURL := url

if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
url = url[strings.Index(url, "/")+2:]
} else {
Expand Down
9 changes: 9 additions & 0 deletions tests/assets/pkg/ScrapeGit/gold/morse-upper.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pkg describe githUb.com/toitware/toit-MoRse 1.0.6
Exit Code: 0
morse:
description: Functions for International (ITU) Morse code.
url: github.com/toitware/toit-morse
version: 1.0.6
license: MIT
hash: f9f6ba3a04984db16887d7a1051ada8ad30d7db2

4 changes: 4 additions & 0 deletions tests/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ func (pt PkgTest) ToitNegative(args ...string) string {
func (pt PkgTest) normalizeGold(gold string) string {
gitDir := computeGitDir(pt.dir)
gold = strings.ReplaceAll(gold, gitDir, "<GIT_URL>")
gold = strings.ReplaceAll(gold, strings.ToLower(gitDir), "<GIT_URL>")
// When showing lock-file entries we might also see escaped git entries.
// We can't use a different replacement, as the escaping is dependent on the OS.
escapedGitURL := string(compiler.ToURIPath(gitDir))
Expand Down Expand Up @@ -1437,6 +1438,9 @@ func test_toitPkg(t *tedi.T) {
pt.GoldToit("morse", [][]string{
{"pkg", "describe", "github.com/toitware/toit-morse", "1.0.6"},
})
pt.GoldToit("morse-upper", [][]string{
{"pkg", "describe", "githUb.com/toitware/toit-MoRse", "1.0.6"},
})
pt.GoldToit("https_morse", [][]string{
{"pkg", "describe", "https://github.com/toitware/toit-morse", "1.0.6"},
})
Expand Down

0 comments on commit 85991d7

Please sign in to comment.