Verschaerfe Pruefung auf ganze positive Eintragsnummern

- Fuegt isPositiveInteger() hinzu fuer Validierung von Eintragsnummern
- nextEntryId und entry.entryId muessen ganze Zahlen >= 1 sein
- Akzeptiert nicht mehr negative, gebrochene oder Null-Werte
- Vier neue Tests pruefen die verstaerkten Anforderungen
- Alle bestehenden Tests bleiben gruen

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
vchuser
2026-07-28 16:16:55 +02:00
co-authored by Claude Opus 5
parent 5966aab6b6
commit 330beaeffe
2 changed files with 46 additions and 2 deletions
+6 -2
View File
@@ -24,6 +24,10 @@ function isFiniteNumber(value) {
return typeof value === 'number' && Number.isFinite(value); return typeof value === 'number' && Number.isFinite(value);
} }
function isPositiveInteger(value) {
return typeof value === 'number' && Number.isInteger(value) && value >= 1;
}
function isUsableStack(stack) { function isUsableStack(stack) {
return ( return (
isPlainObject(stack) isPlainObject(stack)
@@ -36,7 +40,7 @@ function isUsableStack(stack) {
function isUsableEntry(entry) { function isUsableEntry(entry) {
return ( return (
isPlainObject(entry) isPlainObject(entry)
&& isFiniteNumber(entry.entryId) && isPositiveInteger(entry.entryId)
&& typeof entry.stackId === 'string' && typeof entry.stackId === 'string'
&& isPlainObject(entry.spec) && isPlainObject(entry.spec)
); );
@@ -65,7 +69,7 @@ export function loadSession(store) {
if (!raw) return null; if (!raw) return null;
const parsed = JSON.parse(raw); const parsed = JSON.parse(raw);
if (!Array.isArray(parsed.stacks) || !Array.isArray(parsed.entries)) return null; if (!Array.isArray(parsed.stacks) || !Array.isArray(parsed.entries)) return null;
if (!isFiniteNumber(parsed.nextEntryId)) return null; if (!isPositiveInteger(parsed.nextEntryId)) return null;
if (!parsed.stacks.every(isUsableStack)) return null; if (!parsed.stacks.every(isUsableStack)) return null;
if (!parsed.entries.every(isUsableEntry)) return null; if (!parsed.entries.every(isUsableEntry)) return null;
+40
View File
@@ -191,3 +191,43 @@ test('nach Sichern und Laden funktioniert Weiterarbeiten weiterhin', () => {
assert.equal(wieder.entries.find((e) => e.entryId === zweiterEintrag.entryId), undefined); assert.equal(wieder.entries.find((e) => e.entryId === zweiterEintrag.entryId), undefined);
assert.equal(wieder.stacks.find((s) => s.id === 'B'), undefined); assert.equal(wieder.stacks.find((s) => s.id === 'B'), undefined);
}); });
test('nextEntryId als negative Zahl liefert null', () => {
const store = fakeStore();
store.setItem('ram-sortierhilfe:session', JSON.stringify({
stacks: [],
entries: [],
nextEntryId: -5,
}));
assert.equal(loadSession(store), null);
});
test('nextEntryId als gebrochene Zahl liefert null', () => {
const store = fakeStore();
store.setItem('ram-sortierhilfe:session', JSON.stringify({
stacks: [],
entries: [],
nextEntryId: 1.5,
}));
assert.equal(loadSession(store), null);
});
test('nextEntryId als Null liefert null', () => {
const store = fakeStore();
store.setItem('ram-sortierhilfe:session', JSON.stringify({
stacks: [],
entries: [],
nextEntryId: 0,
}));
assert.equal(loadSession(store), null);
});
test('Eintrag mit gebrochener entryId liefert null', () => {
const store = fakeStore();
store.setItem('ram-sortierhilfe:session', JSON.stringify({
stacks: [{ id: 'A', count: 1, spec: emptySpec() }],
entries: [{ entryId: 1.5, stackId: 'A', spec: emptySpec(), source: 'barcode' }],
nextEntryId: 2,
}));
assert.equal(loadSession(store), null);
});