Skip to content

Make AssetPath::get_full_extension work for non-UTF-8 file names. #19974

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 4 commits into
base: main
Choose a base branch
from

Conversation

yrns
Copy link
Contributor

@yrns yrns commented Jul 6, 2025

Objective

The expectation is that extensions will be UTF-8 in order to match asset loaders, but if the file name itself is not, it should still work. This fixes that.

Solution

This works on bytes and returns &str instead of allocating a String. The changes outside of the function itself relate to the return type changing.

Testing

cargo test --workspace --tests

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Assets Load files from disk to use for things like images, models, and sounds S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 6, 2025
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

I like this fix, but two small requests:

  1. Please add a regression test.
  2. Please add a simple migration guide.

@alice-i-cecile alice-i-cecile added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Jul 6, 2025
Copy link
Contributor

github-actions bot commented Jul 6, 2025

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Please review the instructions for writing migration guides, then expand or revise the content in the migration guides directory to reflect your changes.

@yrns
Copy link
Contributor Author

yrns commented Jul 6, 2025

  1. Please add a regression test.

I'm on Linux. I'm not sure there's a way to write this in a platform-independent way. I think it works for Mac, too. I'm not sure about others.

@alice-i-cecile
Copy link
Member

We could cfg flag the test based on the platform? @viridia or @andriyDev might have better advice.

@andriyDev
Copy link
Contributor

I wonder if this change is worth making... In the future, we expect to make AssetPath just hold a String and then leave any platform specifics to AssetSources. This would result in a regression here, since users could start depending on these non-UTF-8 file names.

I think my (very weak) opinion is that we should not fix this since it's not where we want to go long term anyway? @alice-i-cecile thoughts?

As for the cfg flagging the test, I can't think of anything other than using OsString::from_encoded_bytes_unchecked and some unsafe. I think that's too much risk just for a test, so only making it work on Unix sounds fine to me.

@viridia
Copy link
Contributor

viridia commented Jul 6, 2025

I share @andriyDev's concerns. The way that I have always seen assets as working is that assets should live in a virtual, platform-neutral filesystem that is backed by one or more actual, platform-specific filesystems. Part of the job of this virtual filesystem is to completely isolate any platform differences. This means that things like windows drive letters should be meaningless in an asset path; it's only the AssetSource that knows anything about filesystem roots. It's the job of AssetSource to translate an asset path into a corresponding filesystem path, and that translation ought to include any necessary swizzling of character encodings. Either that, or asset paths should be checked to ensure that data conforms to the "least common denominator" character encoding for all platforms.

@alice-i-cecile alice-i-cecile added S-Needs-Design This issue requires design work to think about how it would best be accomplished X-Contentious There are nontrivial implications that should be thought through and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Bug An unexpected or incorrect behavior M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Needs-Design This issue requires design work to think about how it would best be accomplished X-Contentious There are nontrivial implications that should be thought through
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants