Skip to content

Commit

Permalink
validate reference urls are unique
Browse files Browse the repository at this point in the history
  • Loading branch information
clemiller committed Sep 30, 2024
1 parent 0412895 commit cb18228
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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";
}
Expand Down

0 comments on commit cb18228

Please sign in to comment.