Skip to content

Commit 4d92b93

Browse files
committed
description-resolver addsextra repair that extracts simple strings from the Authors field, preventing DataCite objects from corrupting DOI registration XML
1 parent 380c6ee commit 4d92b93

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/openneuro-server/src/datalad/description.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,22 @@ export const repairDescriptionTypes = (description) => {
5858
for (const field of arrayStringFields) {
5959
if (Object.hasOwn(description, field)) {
6060
if (!isArrayOfStrings(description[field])) {
61-
// If it's not an array of strings (or not an array at all), replace with an empty array
62-
newDescription[field] = []
61+
// Check if the array is corrupted with objects (DataCite flow)
62+
if (Array.isArray(description[field])) {
63+
newDescription[field] = description[field]
64+
.map((item) => {
65+
// If item is an object with a 'name' field (DataCite contributor), extract the name.
66+
if (typeof item === "object" && item !== null && item.name) {
67+
return String(item.name)
68+
}
69+
// Otherwise, attempt to stringify the item (might still produce garbage, but defensive)
70+
return String(item)
71+
})
72+
.filter((s) => typeof s === "string" && s.trim().length > 0) // Keep only clean strings
73+
} else {
74+
// If it's not an array at all, replace with an empty array (original logic)
75+
newDescription[field] = []
76+
}
6377
}
6478
// If it is already a valid array of strings, no change is needed.
6579
}

0 commit comments

Comments
 (0)