Skip to content

Commit a236281

Browse files
authored
Merge pull request #24 from per1234/handle-root-submission-url
Handle root submission URLs
2 parents 86b2f0e + 61ea224 commit a236281

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

main.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,10 @@ func populateSubmission(submissionURL string, listPath *paths.Path) (submissionT
355355
// normalizeURL converts the URL into the standardized format used in the index.
356356
func normalizeURL(rawURL *url.URL) url.URL {
357357
normalizedPath := strings.TrimRight(rawURL.Path, "/")
358-
if !strings.HasSuffix(normalizedPath, ".git") {
358+
if normalizedPath == "" {
359+
// It doesn't make sense to add the extension to root URLs
360+
normalizedPath = "/"
361+
} else if !strings.HasSuffix(normalizedPath, ".git") {
359362
normalizedPath += ".git"
360363
}
361364

@@ -392,11 +395,15 @@ func uRLIsUnder(childURL url.URL, parentCandidates []string) bool {
392395
panic(err)
393396
}
394397

395-
isUnderPath, err := paths.New(childURL.Path).IsInsideDir(paths.New(parentCandidateURL.Path))
398+
childURLPath := paths.New(childURL.Path)
399+
candidateURLPath := paths.New(parentCandidateURL.Path)
400+
401+
isUnderPath, err := childURLPath.IsInsideDir(candidateURLPath)
396402
if err != nil {
397403
panic(err)
398404
}
399-
if (childURL.Host == parentCandidateURL.Host) && isUnderPath {
405+
406+
if (childURL.Host == parentCandidateURL.Host) && (childURLPath.EqualsTo(candidateURLPath) || isUnderPath) {
400407
return true
401408
}
402409
}

main_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ func Test_normalizeURL(t *testing.T) {
158158
{".git suffix", "https://github.com/foo/bar.git", "https://github.com/foo/bar.git"},
159159
{"http://", "http://github.com/foo/bar", "https://github.com/foo/bar.git"},
160160
{"git://", "git://github.com/foo/bar", "https://github.com/foo/bar.git"},
161+
{"Root URL", "https://github.com", "https://github.com/"},
162+
{"Root URL with trailing slash", "https://github.com/", "https://github.com/"},
161163
}
162164

163165
for _, testTable := range testTables {
@@ -196,6 +198,8 @@ func Test_uRLIsUnder(t *testing.T) {
196198
{"Mismatch, root path", "https://github.com/foo/bar", []string{"example.com", "example.org"}, assert.False},
197199
{"Match, subfolder", "https://github.com/foo/bar", []string{"example.com/foo", "github.com/foo"}, assert.True},
198200
{"Mismatch, subfolder", "https://github.com/foo/bar", []string{"example.com/foo", "github.org/bar"}, assert.False},
201+
{"Match, root child URL", "https://github.com/", []string{"example.com", "github.com"}, assert.True},
202+
{"Mismatch, root child URL", "https://github.com/", []string{"example.com", "github.org"}, assert.False},
199203
}
200204

201205
for _, testTable := range testTables {

0 commit comments

Comments
 (0)