-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
AssetPath source parse fix #11543
AssetPath source parse fix #11543
Conversation
It looks like the error type was not actually removed? I see a removed test but it sounded like you meant to remove an |
diff --git a/crates/bevy_asset/src/path.rs b/crates/bevy_asset/src/path.rs
index 689913169..9b4b68bb6 100644
--- a/crates/bevy_asset/src/path.rs
+++ b/crates/bevy_asset/src/path.rs
@@ -135,7 +135,7 @@ impl<'a> AssetPath<'a> {
let mut label_range = None;
while let Some((index, char)) = chars.next() {
match char {
- ':' => {
+ ':' if source_range.is_none() => {
let (_, char) = chars
.next()
.ok_or(ParseAssetPathError::InvalidSourceSyntax)?; Seems like something like this could fix it, and avoid scanning the path twice. |
My bad, you're correct. I've removed the error variant now. |
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.
I wouldn't be opposed to heavy commenting of this entire function, but your test case clearly demonstrates both the problem and that your fix works.
This still doesn't fix the issue of In any case, is using |
Does it not? The test you added passes with that change. (If not, another test would be nice)
This code isn't likely to be in a hot path, so probably not, but most asset paths at the moment use the default source with no label. |
I'll add another test to show that case.
Good point, you are right that if an
Maybe with some good comments though, it wouldn't matter too much if the function implementation itself is a bit messy. |
I thought it was worth discussing, because the single-passness was touted here: #9885 when that code was added. I'm not personally sure how much it matters. The error being removed doesn't seem super useful, and I'm not sure that the optimization would make a difference in any real-world uses. Either way, this seems like a high priority bug to fix, so I'm happy as long as the test coverage is there for future refactoring. |
Yeah, I'm much more concerned with correctness and tests than performance here. We can refactor later if it shows up. |
…ase and added appropriate error types and tests.
Does this branch also close #11271? |
Not quite, but it does help. This PR will allow the path portion of the The options for an absolute path would either be to:
|
I changed it back to a single pass algorithm. It's a bit messy, but hopefully the comments I've added are enough to clarify the behavior. I've also discovered a couple new error cases:
To account for these two error cases, I've forbidden |
Remember to update the PR description with the final set of changes :) |
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.
This seems to accept both empty strings ""
and pathless strings "source://#label"
. Is this intended behavior?
This is consistent with the prior behavior. The |
# Objective Fixes bevyengine#11533 When `AssetPath`s are created from a string type, they are parsed into an `AssetSource`, a `Path`, and a `Label`. The current method of parsing has some unnecessary quirks: - The presence of a `:` character is assumed to be the start of an asset source indicator. - This is not necessarily true. There are valid uses of a `:` character in an asset path, for example an http source's port such as `localhost:80`. - If there are multiple instances of `://`, the last one is assumed to be the asset source deliminator. - This has some unexpected behavior. Even in a fully formed path, such as `http://localhost:80`, the `:` between `localhost` and `80` is assumed to be the start of an asset source, causing an error since it does not form the full sequence `://`. ## Solution Changes the `AssetPath`'s `parse_internal` method to be more permissive. - Only the exact sequence `://` is taken to be the asset source deliminator, and only the first one if there are multiple. - As a consequence, it is no longer possible to detect a malformed asset source deliminator, and so the corresponding error was removed.
Objective
Fixes #11533
When
AssetPath
s are created from a string type, they are parsed into anAssetSource
, aPath
, and aLabel
.The current method of parsing has some unnecessary quirks:
:
character is assumed to be the start of an asset source indicator.:
character in an asset path, for example an http source's port such aslocalhost:80
.://
, the last one is assumed to be the asset source deliminator.http://localhost:80
, the:
betweenlocalhost
and80
is assumed to be the start of an asset source, causing an error since it does not form the full sequence://
.#
is used to determine the asset label, and all further parsing and validation stops there.Solution
Changes the
AssetPath
'sparse_internal
method to be more permissive.://
is taken to be the asset source delimiter, and only the first one if there are multiple.#
is taken to be the asset label delimiter.#
cannot be contained in the asset source.://
cannot be contained in the asset label.The
ParseAssetPathError
enum and the doc tests have been updated to reflect these new conditions.