Skip to content

Commit b4d8daf

Browse files
committed
fix: guard non-string writing_preset against TypeError on load
Eine manuell editierte config.json mit einem unhashbaren Wert (Liste/Objekt) für workflows.writing_preset löste in _validate_and_sanitize einen TypeError aus (`value not in set` hasht den Wert) und brach den Start ab, statt auf "standard" zurückzufallen. Jetzt wird zuerst der String-Typ geprüft. Adressiert Codex-PR-Review (P2) auf PR #5.
1 parent 81c27b8 commit b4d8daf

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

app/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ def _validate_and_sanitize(self) -> None:
337337
wf["text_improver_tone"] = "neutral"
338338
if wf.get("emoji_density") not in VALID_EMOJI_DENSITIES:
339339
wf["emoji_density"] = "mittel"
340-
if wf.get("writing_preset") not in VALID_WRITING_PRESETS:
340+
preset_value = wf.get("writing_preset")
341+
if not isinstance(preset_value, str) or preset_value not in VALID_WRITING_PRESETS:
341342
wf["writing_preset"] = DEFAULT_PRESET_KEY
342343
wf["custom_terms"] = _sanitize_terms(wf.get("custom_terms"))
343344

tests/test_config.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ def test_missing_preset_key_defaults_to_standard(self, config_dir):
120120
assert loaded.writing_preset == "standard"
121121
assert loaded.text_improver_tone == "formal"
122122

123+
@pytest.mark.parametrize("bad_value", [[], {}, ["email_formal"], 42, None, True])
124+
def test_non_string_preset_value_is_coerced_without_crash(self, config_dir, bad_value):
125+
# Manuell editierte config.json mit unhashbarem/falschem Typ darf den
126+
# Start nicht mit TypeError abbrechen, sondern auf "standard" zurückfallen.
127+
config_dir.mkdir(parents=True, exist_ok=True)
128+
(config_dir / "config.json").write_text(
129+
json.dumps({"workflows": {"writing_preset": bad_value}}),
130+
encoding="utf-8",
131+
)
132+
133+
loaded = BlitztextConfig(config_dir=config_dir)
134+
assert loaded.writing_preset == "standard"
135+
123136

124137
class TestTranscriptionHotkey:
125138
def test_valid_hotkey_is_accepted(self, config):

0 commit comments

Comments
 (0)