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 <[email protected]> Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
This commit is contained in:
1 parent
aa8319a1db
commit
f0aac594c3
2 files changed
+3
-2
No files matched your search
@@ -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"
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user