better handling in the validation logic
This commit is contained in:
parent
dfe63f4542
commit
7edfb9d762
@ -123,11 +123,39 @@ function validateCollectionDisplay(display) {
|
|||||||
return "Display must be an object";
|
return "Display must be an object";
|
||||||
}
|
}
|
||||||
if (display) {
|
if (display) {
|
||||||
if (display.ordering && !["manual", "alpha"].includes(display.ordering)) {
|
// Normalize ordering and show_badge in case the YAML parser left inline comments
|
||||||
return "Display ordering must be 'manual' or 'alpha'";
|
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") {
|
|
||||||
return "Display show_badge must be 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;
|
return null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user