Skip to content

fix: Add 'utf-8' encoding to output .ts open calls to prevent UnicodeDecodeError #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pydantic2ts/cli/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _clean_output_file(output_filename: str) -> None:
By rolling them all up into a single model, we can generate a single output file.
2. Add a banner comment with clear instructions for regenerating the typescript definitions.
"""
with open(output_filename, "r") as f:
with open(output_filename, "r", encoding="utf-8") as f:
lines = f.readlines()

start, end = None, None
Expand All @@ -233,7 +233,7 @@ def _clean_output_file(output_filename: str) -> None:

new_lines = banner_comment_lines + lines[:start] + lines[(end + 1) :]

with open(output_filename, "w") as f:
with open(output_filename, "w", encoding="utf-8") as f:
f.writelines(new_lines)


Expand Down