Skip to content

Commit 4d7bf68

Browse files
šŸ› Harden QuantumCircuitViewer zoom with localStorage guards and named constants (#15940)
Fixes #15935 Adds CIRCUIT_ZOOM_MIN_PCT=15 and CIRCUIT_ZOOM_MAX_PCT=150 named constants; updates readPersistedZoom validation to check explicit bounds instead of parsed <= 0. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b20d15a commit 4d7bf68

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

ā€Žweb/src/components/cards/quantum/QuantumCircuitViewer.tsxā€Ž

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { CIRCUIT_ZOOM_STORAGE_KEY } from './QuantumCircuitViewer.constants'
1212

1313
const CIRCUIT_ASCII_POLLING_INTERVAL_MS = QUANTUM_CIRCUIT_DEFAULT_POLL_MS
1414
const CIRCUIT_ZOOM_DEFAULT_PCT = 100
15+
const CIRCUIT_ZOOM_MIN_PCT = 15
16+
const CIRCUIT_ZOOM_MAX_PCT = 150
1517
const CIRCUIT_ZOOM_PERCENT_DIVISOR = 100
1618
const CIRCUIT_POPOUT_URL = '/api/quantum/qasm/circuit/ascii'
1719
const CIRCUIT_ZOOM_LEVELS_PCT = [15, 20, 25, 35, 50, 65, 85, 100, 125, 150]
@@ -37,7 +39,9 @@ function readPersistedZoom(): number {
3739
const stored = window.localStorage.getItem(CIRCUIT_ZOOM_STORAGE_KEY)
3840
if (!stored) return CIRCUIT_ZOOM_DEFAULT_PCT
3941
const parsed = parseInt(stored, 10)
40-
if (!Number.isFinite(parsed) || parsed <= 0) return CIRCUIT_ZOOM_DEFAULT_PCT
42+
if (!Number.isFinite(parsed) || parsed < CIRCUIT_ZOOM_MIN_PCT || parsed > CIRCUIT_ZOOM_MAX_PCT) {
43+
return CIRCUIT_ZOOM_DEFAULT_PCT
44+
}
4145
return snapToNearestZoom(parsed)
4246
} catch {
4347
return CIRCUIT_ZOOM_DEFAULT_PCT

0 commit comments

Comments
Ā (0)