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

Set UTF-8 for all ConfigObj instances #8240

Merged
merged 1 commit into from
Nov 1, 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
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ def from_defaults(settings: TriblerConfigManager) -> DownloadConfig:
Create a new download config from the given Tribler configuration.
"""
spec_file_name = DownloadConfig.get_spec_file_name(settings)
defaults = ConfigObj(StringIO(SPEC_CONTENT))
defaults = ConfigObj(StringIO(SPEC_CONTENT), encoding="utf-8")
defaults["filename"] = spec_file_name
Path(spec_file_name).parent.mkdir(parents=True, exist_ok=True) # Required for the next write
with open(spec_file_name, "wb") as spec_file:
defaults.write(spec_file)
defaults = ConfigObj(StringIO(), configspec=spec_file_name)
defaults = ConfigObj(StringIO(), configspec=spec_file_name, encoding="utf-8")
defaults.validate(Validator())
config = DownloadConfig(defaults)

Expand All @@ -147,7 +147,7 @@ def copy(self) -> DownloadConfig:
"""
Create a copy of this config.
"""
return DownloadConfig(ConfigObj(self.config))
return DownloadConfig(ConfigObj(self.config, encoding="utf-8"))

def write(self, filename: Path) -> None:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,8 @@ async def load_checkpoint(self, filename: Path | str) -> bool:
Load a checkpoint from a given file name.
"""
try:
conf_obj = ConfigObj(str(filename), configspec=DownloadConfig.get_spec_file_name(self.config))
conf_obj = ConfigObj(str(filename), configspec=DownloadConfig.get_spec_file_name(self.config),
encoding="utf-8")
conf_obj.validate(Validator())
config = DownloadConfig(conf_obj)
except Exception:
Expand Down
5 changes: 4 additions & 1 deletion src/tribler/ui/src/dialogs/SaveAs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,11 @@ export default function SaveAs(props: SaveAsProps & JSX.IntrinsicAttributes & Di

if (response === undefined) {
setError(`${t("ToastErrorGetMetainfo")} ${t("ToastErrorGenNetworkErr")}`);
} else if ('error' in response && typeof response.error === 'object') {
let errorCode = response.error as {handled: boolean, code: string, message: string};
setError(`${t("ToastErrorGetMetainfo")} ${errorCode.code}`);
} else if (isErrorDict(response)) {
setError(`t("ToastErrorGetMetainfo")} ${response.error}`);
setError(`${t("ToastErrorGetMetainfo")} ${response.error}`);
Comment on lines +158 to +162
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit icky, but for the scope of this PR I decided not to make our custom REST API errors consistent with the unhandled errors.

} else if (response) {
const info = getFilesFromMetainfo(response.metainfo);
var files = info.files;
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/upgrade_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _import_7_14_settings(src: str, dst: TriblerConfigManager) -> None:
"""
Read the file at the source path and import its settings.
"""
old = ConfigObj(src)
old = ConfigObj(src, encoding="utf-8")
_copy_if_exists(old, "api/key", dst, "api/key")
_copy_if_exists(old, "api/http_enabled", dst, "api/http_enabled")
_copy_if_exists(old, "api/https_enabled", dst, "api/https_enabled")
Expand Down