Skip to content

Handle root submission URLs #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,10 @@ func populateSubmission(submissionURL string, listPath *paths.Path) (submissionT
// normalizeURL converts the URL into the standardized format used in the index.
func normalizeURL(rawURL *url.URL) url.URL {
normalizedPath := strings.TrimRight(rawURL.Path, "/")
if !strings.HasSuffix(normalizedPath, ".git") {
if normalizedPath == "" {
// It doesn't make sense to add the extension to root URLs
normalizedPath = "/"
} else if !strings.HasSuffix(normalizedPath, ".git") {
normalizedPath += ".git"
}

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

isUnderPath, err := paths.New(childURL.Path).IsInsideDir(paths.New(parentCandidateURL.Path))
childURLPath := paths.New(childURL.Path)
candidateURLPath := paths.New(parentCandidateURL.Path)

isUnderPath, err := childURLPath.IsInsideDir(candidateURLPath)
if err != nil {
panic(err)
}
if (childURL.Host == parentCandidateURL.Host) && isUnderPath {

if (childURL.Host == parentCandidateURL.Host) && (childURLPath.EqualsTo(candidateURLPath) || isUnderPath) {
return true
}
}
Expand Down
4 changes: 4 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ func Test_normalizeURL(t *testing.T) {
{".git suffix", "https://github.com/foo/bar.git", "https://github.com/foo/bar.git"},
{"http://", "http://github.com/foo/bar", "https://github.com/foo/bar.git"},
{"git://", "git://github.com/foo/bar", "https://github.com/foo/bar.git"},
{"Root URL", "https://github.com", "https://github.com/"},
{"Root URL with trailing slash", "https://github.com/", "https://github.com/"},
}

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

for _, testTable := range testTables {
Expand Down