fix(stats): validate max-titles against allowlist instead of positive-in

- `loadMaxTitles` now rejects values not in `MAX_TITLES_OPTIONS` (e.g. arbitrary integers like 8)
- Add test covering unsupported-but-numeric stored values
This commit is contained in:
2026-07-06 01:15:24 -07:00
parent 42433dc30b
commit 1cead99c98
3 changed files with 18 additions and 3 deletions
+4
View File
@@ -0,0 +1,4 @@
type: fixed
area: stats
- Show all trend chart titles by default, persist hidden-title choices, and add a per-chart top-title limit selector.
@@ -107,11 +107,22 @@ test('max titles preference round-trips and clears when set to null', () => {
}
});
test('loadMaxTitles rejects non-positive or non-numeric stored values', () => {
const { restore } = installLocalStorage({ 'subminer-stats-trends-max-titles': 'banana' });
test('loadMaxTitles rejects unsupported stored values', () => {
const { restore } = installLocalStorage({ 'subminer-stats-trends-max-titles': '8' });
try {
assert.equal(loadMaxTitles(), null);
} finally {
restore();
}
});
test('loadMaxTitles rejects non-positive or non-numeric stored values', () => {
for (const storedValue of ['0', 'banana']) {
const { restore } = installLocalStorage({ 'subminer-stats-trends-max-titles': storedValue });
try {
assert.equal(loadMaxTitles(), null);
} finally {
restore();
}
}
});
@@ -37,7 +37,7 @@ export function loadMaxTitles(): number | null {
const raw = getStorage()?.getItem(MAX_TITLES_KEY);
if (raw === null || raw === undefined) return null;
const value = Number(raw);
return Number.isInteger(value) && value > 0 ? value : null;
return (MAX_TITLES_OPTIONS as readonly number[]).includes(value) ? value : null;
} catch {
return null;
}