From f0aac594c3067919e0d23ab130bc0eb8f08810c7 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Fri, 4 Dec 2026 19:50:55 +0000 Subject: [PATCH] fix(install): reject NaN and Infinity in existing settings Python's JSON parser accepts them, so an invalid settings file was rewritten instead of being refused and left untouched. Refs: #280 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi --- scripts/merge-json.py | 3 ++- tests/test-install.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/merge-json.py b/scripts/merge-json.py index febf64c..1d98c21 100644 --- a/scripts/merge-json.py +++ b/scripts/merge-json.py @@ -21,7 +21,8 @@ def merged_text(src_text, dest): existing = json.load(f) if not isinstance(existing, dict): raise ValueError("top level is not a JSON object") - before = json.dumps(existing, indent=2, ensure_ascii=False) + # json.load accepts NaN and Infinity, which are not valid JSON. + before = json.dumps(existing, indent=2, ensure_ascii=False, allow_nan=False) after = json.dumps(merge(existing, json.loads(src_text)), indent=2, ensure_ascii=False) return None if after == before else after + "\n" diff --git a/tests/test-install.sh b/tests/test-install.sh index 6cfa7d3..3b08809 100755 --- a/tests/test-install.sh +++ b/tests/test-install.sh @@ -147,7 +147,7 @@ else fail "a second run changed the merged settings" fi -for invalid in '{"model": "opus",' '["not an object"]' ''; do +for invalid in '{"model": "opus",' '["not an object"]' '{"x": NaN}' ''; do BAD_HOME="$(new_home)" BAD="$BAD_HOME/.claude/settings.json" printf '%s' "$invalid" > "$BAD"