fix: mirror #734 onto decomposed files (PG NaN slideshow seed, SQLite bool renders)

Same two pre-existing-on-main bugs, at their post-decomposition
locations: clampIntOrUndefined in adminEvents/crud.js slideshow seed;
!! coercion in EventDetailsHeader, EventInformationCard,
ClientAccessCard. Keeps this branch correct in either merge order with
#734 — when merging main afterwards, resolve the adminEvents.js
modify/delete conflict by keeping the deletion.
This commit is contained in:
Paul Nothaft
2026-07-03 09:01:01 +02:00
parent 2ea26a4962
commit 766351b588
6 changed files with 81 additions and 7 deletions
+17 -1
View File
@@ -31,4 +31,20 @@ function ensureNumber(value, fallback = 0) {
return Number.isFinite(n) ? n : fallback;
}
module.exports = { ensureInt, ensureNumber };
/**
* Parse a value as an integer clamped to [min, max]; `undefined` on
* anything that doesn't parse (null, undefined, '', booleans, garbage).
*
* Exists because the inline guard `Number.isFinite(+v) ? parseInt(v)`
* disagrees with itself for null/''/true (`+null` is 0 but
* `parseInt(null)` is NaN), which let NaN through Math.min/Math.max
* and into an INSERT — PostgreSQL rejects NaN for integer columns
* while SQLite silently stores NULL, so it only failed on PG.
*/
function clampIntOrUndefined(value, min, max) {
const n = parseInt(value, 10);
if (!Number.isFinite(n)) return undefined;
return Math.min(max, Math.max(min, n));
}
module.exports = { ensureInt, ensureNumber, clampIntOrUndefined };