Repository navigation
Conversation
|
✅ Human Attestation: @Jinyong-Li attested this PR at commit
Later pushes to this PR stay attested. Attestation page |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
| if "\n" in comment or "\r" in comment: | ||
| raise ValueError("Comment cannot contain line breaks") |
There was a problem hiding this comment.
Why not move these two lines into the validation function as well?
There was a problem hiding this comment.
Thanks for the suggestion! I‘ve moved those checks into validate_comment().
Summary
The comment-writing APIs currently accept control characters that TOML forbids. For example, copying ANSI-colored log text into a comment emits ESC into the document; both
tomlkit.parse()and Python'stomllib.loads()then reject the saved output:Validate comment characters before changing an item or array.
comment(),Item.comment(), andArray.add_line(comment=...)now raiseValueErrorfor forbidden controls. Tabs and Unicode text remain valid, and standalone multiline comments retain LF/CRLF endings. Bare carriage returns in the input are rejected. This follows the TOML comment rules.The tests cover every forbidden ASCII control other than the separately handled line endings, all three public entry points, preservation of existing data after rejection, and valid Unicode/line-ending controls. On unmodified master, 93 of the new cases fail and 3 pass.
Validation on Windows / CPython 3.13.5:
python -m pytest -q tests: 1,421 passed, including the initializedtoml-testcorpus.git diff --check: passed.mypy tomlkit tests/test_api.pywith mypy 1.19.1 reports the same 7 existing errors on this patch and an unchanged checkout of55d0768; no new diagnostics.Duplicate Check
validate_comment, and inspected the open PR list. Prefix every line of a multiline comment with # #511 adds multiline comment rendering; this patch validates the characters passed to the comment-writing APIs.Agent Drafting Metadata