From cb18228ff01a8eae3d3a4f24f9b6c9de4fba3f3c Mon Sep 17 00:00:00 2001 From: Charissa Miller <48832936+clemiller@users.noreply.github.com> Date: Mon, 30 Sep 2024 17:31:10 -0400 Subject: [PATCH] validate reference urls are unique --- .../reference-edit-dialog.component.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/src/app/components/reference-edit-dialog/reference-edit-dialog.component.ts b/app/src/app/components/reference-edit-dialog/reference-edit-dialog.component.ts index 41af96a8..13ea5f70 100644 --- a/app/src/app/components/reference-edit-dialog/reference-edit-dialog.component.ts +++ b/app/src/app/components/reference-edit-dialog/reference-edit-dialog.component.ts @@ -135,6 +135,10 @@ export class ReferenceEditDialogComponent implements OnInit, OnDestroy { if (!this.reference.url.startsWith('https://') && !this.reference.url.startsWith('http://')) { return false; } + // check new references for uniqueness + if (this.isNew && this.references$.some(x => x.url && this.urlExists(x.url))) { + return false; + } // check for other malformities try { new URL(this.reference.url); @@ -145,10 +149,17 @@ export class ReferenceEditDialogComponent implements OnInit, OnDestroy { return true; } + public urlExists(url) { + return url.replace(/\//g, '') === this.reference.url.replace(/\//g, '') + } + public get URLError(): string { if (this.reference.url) { if (!this.reference.url.startsWith('https://') && !this.reference.url.startsWith('http://')) { return "URL must begin with 'http://' or 'https://'"; + } else if (this.references$.some(x => x.url && this.urlExists(x.url))) { + let citation = this.references$.find(x => x.url && this.urlExists(x.url)); + return `a reference with this URL already exists: (Citation: ${citation.source_name})`; } else { return "malformed URL"; }