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

Fix #12648: Ensure all uses of std::filesystem::path use native encoding. #12650

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PeterN
Copy link
Member

@PeterN PeterN commented May 9, 2024

Motivation / Problem

std::filesystem::path does not expect UTF-8 strings, and it seems may produce invalid results when done so, so they must be converted to native format first (and back to utf-8 after.)

Description

Ensure strings passed to std::filesystem::path go through OTTD2FS conversion, and back to UTF-8 with FS2OTTD after.

Sadly std::filesystem::path will implicitly convert a std::string, so it's difficult to catch all case.

This is not the correct way to deal with this situation. C++20 would like us to use std::u8string everything, but that is not really feasible. So this is a quick & dirty fix without adding too much code.

Maybe fixes #12648 .

Limitations

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@glx22
Copy link
Contributor

glx22 commented May 9, 2024

…e encoding.

std::filesystem::path does not expect UTF-8 strings, so they must be converted to native format first (and back to utf-8 after.)
@PeterN PeterN marked this pull request as ready for review May 25, 2024 16:18
@PeterN PeterN added the backport requested This PR should be backport to current release (RC / stable) label May 25, 2024
@PeterN
Copy link
Member Author

PeterN commented May 25, 2024

Not sure if this fixes all problems but it seems to go some way to help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport requested This PR should be backport to current release (RC / stable)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Crash]: If the directory name contains multibyte characters, openTTD will crash.
2 participants