Skip to content

Escape invalid XML characters in JUnit property names - #15397

Open
ashutosh8021 wants to merge 2 commits into
pytest-dev:mainfrom
ashutosh8021:codex/fix-junit-property-name-escaping
Open

ashutosh8021 wants to merge 2 commits into
pytest-dev:mainfrom
ashutosh8021:codex/fix-junit-property-name-escaping

Conversation

@ashutosh8021

@ashutosh8021 ashutosh8021 commented Nov 15, 2026 •

Copy link
Copy Markdown

Property values in JUnit XML are escaped for invalid XML characters, but property names are not. A NUL in a name produces an unreadable report, and a lone surrogate crashes report writing. This applies the existing escaping helper to names for both record_property and record_testsuite_property.

The tests exercise both fixtures, xUnit 1/2 as supported, invalid characters, and valid Unicode/XML-special characters. Six regression cases fail without the fix; all 160 JUnit XML tests and 24 report tests pass with it. Applicable pre-commit checks, including mypy, pass.

AI disclosure: OpenAI Codex generated the patch, regression tests, and this description. The commit includes AI attribution. The changelog fragment is included.

Copilot AI balanced review requested due to automatic review settings November 15, 2026 12:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 15, 2026

@chrikrah chrikrah left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On base, a NUL in a record_property name produces a report ElementTree cannot parse. On 812b650 the name comes out as na#x00me, so the property is renamed instead of rejected, the same as the value path already does. As far as I can test it, the fix is right.

# exported trees of fc9a7ef (base) and 812b650 (head), Python 3.12.3
# test_p.py: record_property("na\x00me", "v")
$ pytest -q --junitxml=out.xml test_p.py; grep '<property' out.xml; python -c "ET.parse('out.xml')"
base: <property name="na^@me" value="v" />    ParseError: not well-formed (invalid token)
head: <property name="na#x00me" value="v" />  parses
$ pytest -q -n 4 testing/test_junitxml.py
160 passed                    # head
6 failed, 154 passed          # junitxml.py from base, tests kept
# not run: the rest of testing/, mypy

non-blocking: add_attribute still writes str(name) unescaped. record_xml_attribute is experimental, so leaving it out seems fine to me; is that the intent?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants