Skip to content

C++ docs handler reads UTF-8 Doxygen XML using the system text encoding #4924

Description

@dajiaohuang

The C++ mkdocstrings handler opens Doxygen XML in text mode without an encoding at three sites in support/python/mkdocstrings_handlers/cxx/__init__.py (header, compound and namespace loading).

On current main 6226bc70b8e15060a21a281c5ec5f4b91be8582f, building the docs with Python's Windows cp1252 locale fails at the first header-loading site:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 4724

The input chrono_8h.xml declares UTF-8 and contains valid UTF-8 Chinese text. The text-mode stream decodes it using the system locale before ElementTree can process the XML declaration. The same build completes with PYTHONUTF8=1.

Reproduction environment: Windows x64, repository-pinned support/doc-requirements.txt in an isolated Python environment, official Doxygen 1.18.0 on PATH. From the source root, run the environment's Python with UTF-8 mode disabled:

python -X utf8=0 support/mkdocs build --site-dir <output-directory>

Expected: generated XML is decoded according to its encoding declaration, independently of the user's default text codec. Opening each XML stream in binary mode before ET.parse would let the XML parser handle that decoding without changing the document content or dependencies.

This concerns local documentation generation, not C++ runtime formatting or the hosted Ubuntu deployment. The separate locale-description PR #4923 only changes doc/api.md; it does not fix these reads.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions