diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c6bf73..c4866b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/shinylive/_app_json.py b/shinylive/_app_json.py index abca054..a9439f2 100644 --- a/shinylive/_app_json.py +++ b/shinylive/_app_json.py @@ -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: diff --git a/shinylive/_deps.py b/shinylive/_deps.py index 3c7ffe3..80f5c6f 100644 --- a/shinylive/_deps.py +++ b/shinylive/_deps.py @@ -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: @@ -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) diff --git a/shinylive/_url.py b/shinylive/_url.py index fbda2ba..cf0df32 100644 --- a/shinylive/_url.py +++ b/shinylive/_url.py @@ -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: diff --git a/shinylive/_utils.py b/shinylive/_utils.py index 17eba07..af56f0f 100644 --- a/shinylive/_utils.py +++ b/shinylive/_utils.py @@ -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)