Skip to content

docs: use explicit UTF-8 encoding in redirect generation script #7749

@wkd09

Description

@wkd09

What is the doc issue?

Describe the issue

python/docs/redirects/redirects.py reads and writes redirect-related files without specifying an explicit encoding.

The script currently reads redirect_template.html and redirect_urls.txt, then writes generated redirect index.html files using Python's default system encoding.

This is probably fine in most environments, but on some Windows locales where the default encoding is not UTF-8, the script could fail with a UnicodeDecodeError or UnicodeEncodeError if the files contain non-ASCII characters.

This is more of a docs tooling portability issue than a runtime bug.

What do you want to see in the doc?

I think python/docs/redirects/redirects.py should explicitly use encoding="utf-8" when reading and writing text files.

Suggested change:

HTML_REDIRECT_TEMPLATE = HTML_PAGE_TEMPLATE_FILE.open("r", encoding="utf-8").read()

with open(redirect_page_path, "w", encoding="utf-8") as f:
    f.write(redirect_page)

with open(REDIRECT_URLS_FILE, "r", encoding="utf-8") as f:
    lines = f.readlines()

Link to the doc page, if applicable

https://github.com/microsoft/autogen/blob/main/python/docs/redirects/redirects.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions