Ignore censor preference storage errors (#1652)

This commit is contained in:
red person
2026-06-03 08:16:55 +03:00
committed by GitHub
parent 12652581cb
commit 100fd72e7a
2 changed files with 56 additions and 1 deletions

View File

@@ -8,7 +8,13 @@
let _enabled = true; let _enabled = true;
let _observer = null; let _observer = null;
const PREF_KEY = 'odysseus-sensitive-blur'; const PREF_KEY = 'odysseus-sensitive-blur';
const _prefEnabled = () => localStorage.getItem(PREF_KEY) === 'on'; export const _prefEnabled = () => {
try {
return localStorage.getItem(PREF_KEY) === 'on';
} catch (_) {
return false;
}
};
// Patterns that indicate sensitive data // Patterns that indicate sensitive data
const PATTERNS = [ const PATTERNS = [

View File

@@ -0,0 +1,49 @@
import json
import shutil
import subprocess
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parents[1]
pytestmark = pytest.mark.skipif(not shutil.which("node"), reason="node binary not on PATH")
def _node_eval(source: str):
result = subprocess.run(
["node", "--input-type=module", "-e", source],
cwd=ROOT,
check=True,
capture_output=True,
text=True,
)
return json.loads(result.stdout)
def test_censor_pref_falls_back_when_storage_throws():
values = _node_eval(
"""
globalThis.localStorage = {
getItem() { throw new Error('blocked'); }
};
const { _prefEnabled } = await import('./static/js/censor.js');
console.log(JSON.stringify({ enabled: _prefEnabled() }));
"""
)
assert values == {"enabled": False}
def test_censor_pref_reads_enabled_flag():
values = _node_eval(
"""
globalThis.localStorage = {
getItem(key) { return key === 'odysseus-sensitive-blur' ? 'on' : null; }
};
const { _prefEnabled } = await import('./static/js/censor.js');
console.log(JSON.stringify({ enabled: _prefEnabled() }));
"""
)
assert values == {"enabled": True}