Skip to content
Merged
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
14 changes: 8 additions & 6 deletions modules/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ export const ATTACHMENT_TOTAL_WARN_SIZE = 10 * 1024 * 1024;
* with either an existing template or another imported template.
*/
export function analyseImport(importedTemplates, existingTemplates) {
// Accumulates both existing and newly-imported names; used for duplicate
// detection. Note: `valid` may include entries that are also in `duplicates`.
const seenNames = new Map(
// Tracks all names seen so far: pre-seeded with existing template names
// for storage-level dedup, then extended with each processed import for
// intra-import dedup (so two imported templates with the same name both
// land in `duplicates`). Note: `valid` may include entries also in `duplicates`.
const allSeenNames = new Map(
existingTemplates
.filter((t) => t && typeof t.name === "string" && t.name.trim())
.map((t) => [t.name.toLowerCase(), t])
Expand All @@ -72,11 +74,11 @@ export function analyseImport(importedTemplates, existingTemplates) {
invalid++;
continue;
}
const key = (t.name || "").trim().toLowerCase();
if (seenNames.has(key)) {
const key = t.name.trim().toLowerCase();
if (allSeenNames.has(key)) {
duplicates.set(key, t);
}
seenNames.set(key, t);
allSeenNames.set(key, t);
if (t.body != null && typeof t.body !== "string") {
invalid++;
continue;
Expand Down