better handling in the validation logic

This commit is contained in:
Aaron Powell 2025-09-17 14:09:50 +10:00
parent dfe63f4542
commit 7edfb9d762

View File

@ -123,12 +123,40 @@ function validateCollectionDisplay(display) {
return "Display must be an object";
}
if (display) {
if (display.ordering && !["manual", "alpha"].includes(display.ordering)) {
// Normalize ordering and show_badge in case the YAML parser left inline comments
const normalize = (val) => {
if (typeof val !== 'string') return val;
// Strip any inline comment starting with '#'
const hashIndex = val.indexOf('#');
if (hashIndex !== -1) {
val = val.substring(0, hashIndex).trim();
}
// Also strip surrounding quotes if present
if ((val.startsWith("\"") && val.endsWith("\"")) || (val.startsWith("'") && val.endsWith("'"))) {
val = val.substring(1, val.length - 1);
}
return val.trim();
};
if (display.ordering) {
const normalizedOrdering = normalize(display.ordering);
if (!["manual", "alpha"].includes(normalizedOrdering)) {
return "Display ordering must be 'manual' or 'alpha'";
}
if (display.show_badge && typeof display.show_badge !== "boolean") {
}
if (display.show_badge !== undefined) {
const raw = display.show_badge;
const normalizedBadge = normalize(raw);
// Accept boolean or string boolean values
if (typeof normalizedBadge === 'string') {
if (!['true', 'false'].includes(normalizedBadge.toLowerCase())) {
return "Display show_badge must be boolean";
}
} else if (typeof normalizedBadge !== 'boolean') {
return "Display show_badge must be boolean";
}
}
}
return null;
}