Default to compact XML output and make pretty-print opt-in - #382
Merged
vinitkumar merged 9 commits intoAug 12, 2026
Conversation
Contributor
Reviewer's GuideThis PR makes compact XML output the default for both the Json2xml library and CLI, keeps pretty-printing as an explicit opt-in using a hardened XML parser, and updates tests and docs to reflect the new behavior and type contracts. Sequence diagram for Json2xml.to_xml compact vs pretty outputsequenceDiagram
actor Caller
participant Json2xml
participant dicttoxml_fast
participant defusedxml_minidom
Caller->>Json2xml: to_xml()
Json2xml->>dicttoxml_fast: dicttoxml(data, wrapper, root, attr_type, item_wrap, cdata, list_headers)
dicttoxml_fast-->>Json2xml: xml_bytes (UTF-8)
alt pretty is False (default)
Json2xml-->>Caller: xml_bytes (bytes)
else pretty is True (opt_in)
Json2xml->>defusedxml_minidom: parseString(xml_bytes)
defusedxml_minidom-->>Json2xml: xml_dom
Json2xml->>Json2xml: xml_dom.toprettyxml()
Json2xml-->>Caller: xml_text (str)
end
opt invalid XML with pretty=True
defusedxml_minidom-->>Json2xml: [parse error]
Json2xml-->>Caller: InvalidDataError
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #382 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 7 7
Lines 920 1037 +117
==========================================
+ Hits 920 1037 +117
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
minidomon the common path.defusedxml.minidom.parseString) on that opt-in path to mitigate XML parsing risks.Description
Json2xmlconstructor default frompretty: bool = Truetopretty: bool = Falsesoto_xml()returns serializer bytes by default and avoids a second DOM parse. (json2xml/json2xml.py).--prettydefaultFalseand update the argument help text so the CLI opt-in behavior matches the library. (json2xml/cli.py).README.rst,docs/usage.rst, andlat.md/behavioral docs were updated accordingly.pretty=Truewhen exercising the parser branch. (tests/test_json2xml.py,tests/test_cli.py).defusedxml.minidom.parseStringfor hardened parsing to avoid unsafe stdlib minidom usage on the pretty path.Testing
pytest -q tests/test_cli.py, which passed (53 tests passed).Json2xml({'name': 'Ada'}).to_xml()returnsbytesandJson2xml(..., pretty=True).to_xml()returnsstr, which passed (compact-default and explicit-pretty smoke test passed).rufflint checks on the changed modules and they completed without error.pytest -q tests/test_json2xml.py tests/test_cli.pyinitially failed during collection becausexmltodictwas unavailable and dependency installation was blocked by the environment network restrictions, so a complete end-to-end run could not be performed here;lattooling also was unavailable in the environment and could not be executed.Codex Task
Summary by Sourcery
Default Json2xml conversion now returns compact serializer bytes by default, with pretty-printed XML available via explicit opt-in in both the library and CLI.
New Features:
Enhancements: