From 31ba82a9947b71761146ce42ef863a9bdac93b53 Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 29 Apr 2021 07:48:08 -0700 Subject: [PATCH] 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. --- main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.go b/main.go index 46b79dc..318bda6 100644 --- a/main.go +++ b/main.go @@ -129,6 +129,15 @@ func main() { indexerLogsURLs = append(indexerLogsURLs, indexerLogsURL(submission.NormalizedURL)) } + // Check for duplicates within the submission itself. + submissionURLMap := make(map[string]bool) + for submissionIndex, submission := range req.Submissions { + submissionURLMap[submission.NormalizedURL] = true + if len(submissionURLMap) <= submissionIndex { + req.Submissions[submissionIndex].Error = "Submission contains duplicate URLs." + } + } + // Assemble the index entry for the submissions. req.IndexEntry = strings.Join(indexEntries, "%0A")