fix(project): JSONC block-comment stripping can concatenate separate value tokens
Description
_strip_jsonc_comments() deletes block comments without leaving a token separator. Consequently, invalid configuration values can silently become different valid values: {"max_iter":1/*note*/0} becomes {"max_iter":10}, and [tr/*note*/ue] becomes [true].
Reproduction
From a checkout, run this isolated standard-library reproducer (no agents or providers are called):
import ast
import json
from pathlib import Path
p = Path('lib/crewai/src/crewai/project/json_loader.py')
tree = ast.parse(p.read_text(encoding='utf-8'))
node = next(n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name == '_strip_jsonc_comments')
ns = {'JSONProjectError': ValueError}
exec(compile(ast.Module(body=[node], type_ignores=[]), str(p), 'exec'), ns)
for text in ['{"max_iter":1/*note*/0}', '[tr/*note*/ue]', '[1e/*note*/2]', '[-/*note*/1]']:
cleaned = ns['_strip_jsonc_comments'](text)
print(repr(text), '=>', repr(cleaned), '=>', json.loads(cleaned))Expected: invalid adjacent tokens remain invalid and JSON parsing raises. Actual: they concatenate into 10, true, 1e2, and -1 respectively. Comments should separate tokens, not manufacture a token that was absent in the input.
Proposed scope
Add result.append(" ") at the start of the block-comment branch, retaining the existing preservation of newlines and the unterminated-comment error. This does not change strings containing comment-like text, regular JSON, line comments, or trailing-comma handling.
Evidence and environment
- Inspected
lib/crewai/src/crewai/project/json_loader.pyon the default branch, blobc1c95a83a602db2fff3c922ed4fe313e66c5c688. - Python 3.13.5, Linux x86_64, pytest 9.0.2.
- The exact helper body was exercised in an isolated source-excerpt harness, with the error class represented by a local ValueError subclass. The CrewAI package was not installed, and the full project suite and
load_crew()were not run. - Local before/after tests: 4 failed, 7 passed before; 11 passed after the candidate separator change. The cases cover the four token-concatenation inputs, valid comments, string-contained URLs/comment markers, and unterminated comments.
- Searched issues and PRs for JSONC/comment; did not find this specific token-boundary report.
Disclosure required by CONTRIBUTING.md: llm-generated.
Source: crewAIInc/crewAI