mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-07-30 07:21:32 -07:00
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:
@@ -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', () => {
|
test('loadMaxTitles rejects unsupported stored values', () => {
|
||||||
const { restore } = installLocalStorage({ 'subminer-stats-trends-max-titles': 'banana' });
|
const { restore } = installLocalStorage({ 'subminer-stats-trends-max-titles': '8' });
|
||||||
try {
|
try {
|
||||||
assert.equal(loadMaxTitles(), null);
|
assert.equal(loadMaxTitles(), null);
|
||||||
} finally {
|
} finally {
|
||||||
restore();
|
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);
|
const raw = getStorage()?.getItem(MAX_TITLES_KEY);
|
||||||
if (raw === null || raw === undefined) return null;
|
if (raw === null || raw === undefined) return null;
|
||||||
const value = Number(raw);
|
const value = Number(raw);
|
||||||
return Number.isInteger(value) && value > 0 ? value : null;
|
return (MAX_TITLES_OPTIONS as readonly number[]).includes(value) ? value : null;
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user