Skip to content

Commit 31ba82a

Browse files
committed
Check for duplicates within the submission itself
A check for duplication between the submission and the libraries already on the list was already done. However, it is possible that submitters will add the same library twice within a single submission. This was not previously checked for. In addition to causing confusion at a later time for people working directly with the list, it's also possible that allowing duplicates into the list could have harmful implications for the indexer or for Library Manager itself. So it's safest to make a check for duplicates within the submission and return a helpful error message, requiring the submission to contain only unique libraries before accepting it.
1 parent 4bbdbc1 commit 31ba82a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

main.go

+9
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ func main() {
129129
indexerLogsURLs = append(indexerLogsURLs, indexerLogsURL(submission.NormalizedURL))
130130
}
131131

132+
// Check for duplicates within the submission itself.
133+
submissionURLMap := make(map[string]bool)
134+
for submissionIndex, submission := range req.Submissions {
135+
submissionURLMap[submission.NormalizedURL] = true
136+
if len(submissionURLMap) <= submissionIndex {
137+
req.Submissions[submissionIndex].Error = "Submission contains duplicate URLs."
138+
}
139+
}
140+
132141
// Assemble the index entry for the submissions.
133142
req.IndexEntry = strings.Join(indexEntries, "%0A")
134143

0 commit comments

Comments
 (0)