-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 panic when using .load_folder()
with absolute paths
#9490
Conversation
On case-insensitive filesystems (Windows, Mac, NTFS mounted in Linux, etc.), a path can be represented in a multiple ways: - `c:\users\user\rust\assets\hello\world` - `c:/users/user/rust/assets/hello/world` - `C:\USERS\USER\rust\assets\hello\world` If user specifies a path variant that doesn't match asset folder path bevy calculates, `path.strip_prefix()` will fail, as demonstrated below: ```rs dbg!(Path::new("c:/foo/bar/baz").strip_prefix("c:/foo")); // Ok("bar/baz") dbg!(Path::new("c:/FOO/bar/baz").strip_prefix("c:/foo")); // StripPrefixError(()) ``` This commit rewrites the code in question in a way that prefix stripping is no longer necessary.
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
Example |
Just tested some examples, nice change! Edit: This was mistaken on my part, please disregard! |
It will return relative path if It will return absolute path if |
@bushrat011899 if you're happy with the change and think it's ready to merge, can you please leave a review using Github's system? Bevy works on "community reviews", and your opinion will get us halfway there to merging this :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple solution, thanks for making it!
Great, this fixes #5770. |
…#9490) Fixes bevyengine#9458. On case-insensitive filesystems (Windows, Mac, NTFS mounted in Linux, etc.), a path can be represented in a multiple ways: - `c:\users\user\rust\assets\hello\world` - `c:/users/user/rust/assets/hello/world` - `C:\USERS\USER\rust\assets\hello\world` If user specifies a path variant that doesn't match asset folder path bevy calculates, `path.strip_prefix()` will fail, as demonstrated below: ```rs dbg!(Path::new("c:/foo/bar/baz").strip_prefix("c:/foo")); // Ok("bar/baz") dbg!(Path::new("c:/FOO/bar/baz").strip_prefix("c:/foo")); // StripPrefixError(()) ``` This commit rewrites the code in question in a way that prefix stripping is no longer necessary. I've tested with the following paths on my computer: ```rs let res = asset_server.load_folder("C:\\Users\\user\\rust\\assets\\foo\\bar"); dbg!(res); let res = asset_server.load_folder("c:\\users\\user\\rust\\assets\\foo\\bar"); dbg!(res); let res = asset_server.load_folder("C:/Users/user/rust/assets/foo/bar"); dbg!(res); ```
Fixes #9458.
On case-insensitive filesystems (Windows, Mac, NTFS mounted in Linux, etc.), a path can be represented in a multiple ways:
c:\users\user\rust\assets\hello\world
c:/users/user/rust/assets/hello/world
C:\USERS\USER\rust\assets\hello\world
If user specifies a path variant that doesn't match asset folder path bevy calculates,
path.strip_prefix()
will fail, as demonstrated below:This commit rewrites the code in question in a way that prefix stripping is no longer necessary.
I've tested with the following paths on my computer: