Skip to content
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

Load files as UTF-8 #29

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [UNRELEASED]

* Closed #28: On Windows, extended characters were not handled correctly. Files are now always loaded with UTF-8 encoding. (#29)

## [0.3.0] - 2024-04-16

* Updated to Shinylive web assets 0.3.0.
Expand Down
2 changes: 1 addition & 1 deletion shinylive/_app_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def read_app_files(appdir: Path, destdir: Path) -> list[FileContentJson]:

type: Literal["text", "binary"] = "text"
try:
with open(root / filename, "r") as f:
with open(root / filename, "r", encoding="utf-8") as f:
file_content = f.read()
type = "text"
except UnicodeDecodeError:
Expand Down
4 changes: 2 additions & 2 deletions shinylive/_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def shinylive_app_resources(

if json_file is not None:
json_file = Path(json_file)
with open(json_file) as f:
with open(json_file, encoding="utf-8") as f:
file_contents = json.load(f)

if json_content is not None:
Expand Down Expand Up @@ -514,7 +514,7 @@ def _pyodide_lock_data() -> PyodideLockFile:
cached, so if the file changes, it won't register until the Python session is
restarted.
"""
with open(pyodide_lock_json_file(), "r") as f:
with open(pyodide_lock_json_file(), "r", encoding="utf-8") as f:
return json.load(f)


Expand Down
2 changes: 1 addition & 1 deletion shinylive/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ def read_file(file: str | Path, root_dir: str | Path | None = None) -> FileConte
type: Literal["text", "binary"] = "text"

try:
with open(file, "r") as f:
with open(file, "r", encoding="utf-8") as f:
file_content = f.read()
type = "text"
except UnicodeDecodeError:
Expand Down
2 changes: 1 addition & 1 deletion shinylive/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def listdir_recursive(dir: str | Path) -> list[str]:
def copy_file_and_substitute(
src: str | Path, dest: str | Path, *, replacements: Sequence[FromTo]
) -> None:
with open(src, "r") as fin:
with open(src, "r", encoding="utf-8") as fin:
in_content = fin.read()
for from_str, to_str in replacements:
in_content = in_content.replace(from_str, to_str)
Expand Down
Loading