Accept case-insensitive urn:uuid: prefixes when parsing #912
No reviewers
Labels
No labels
breaking
bug
dependencies
good first issue
help wanted
unstable
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-uuid-rs/uuid!912
Loading…
Reference in a new issue
No description provided.
Delete branch "jaideeppyne/fix/urn-prefix-case-insensitive"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
RFC 2141 and RFC 8141 treat both the
urn:scheme and the NID as case-insensitive, so strings such asURN:UUID:...andUrn:Uuid:...are valid URN forms of a UUID.Uuid::parse_strandUrn::from_stronly accepted the lowercaseurn:uuid:prefix. Hex digits were already case-insensitive; this extends the same treatment to the prefix.Adds parser tests and a
uuid!()compile-pass case.This could be something like
bytes[..9].eq_ignore_ascii_case(b"urn:uuid:")Comment addition here is not necessary
We could lift the
ifup into the38 =>pattern here and remove theelsebranch. It'll fall through to the_case.This could just be
&input[9..]As above;
&input[9..]Applied the prefix slice comparison in
cb8b1d5. This is aconst fn, so stable Rust does not allowbytes[..9];bytes.split_at(9).0.eq_ignore_ascii_case(...)is the const-compatible equivalent.Removed the redundant comment in
cb8b1d5.Applied in
cb8b1d5by matching(38, [b'{', s @ .., b'}'])directly, so non-braced inputs fall through to the existing catch-all arm.Kept the equivalent
input.split_at(9).1incb8b1d5because&input[9..]is not stable in thisconst fn; the full all-features test suite passes.Same const constraint applies in
parse_urn:&input[9..]does not compile on stable Rust in aconst fn, so the existingsplit_at(9).1remains.Thanks @jaideeppyne! I just had a few more comments but it's getting closer now.
@ -87,10 +87,11 @@ impl<'a> InvalidUuid<'a> {return Error(ErrorKind::ParseChar { character, index });The
errormodule doesn't already depend onparser, it's an alternative implementation. I think we should removeis_urn_prefixaltogether and inline the calls toascii_eq_ignore_casewhere it's used now that it's just a single function call.This is the only branch that needs a length check or
split_at_checked, since we already check lengths in the other cases.slop: Unnecessary comment update
@ -87,10 +87,11 @@ impl<'a> InvalidUuid<'a> {return Error(ErrorKind::ParseChar { character, index });Updated in
5055fd4: removed is_urn_prefix and inlined eq_ignore_ascii_case at each parser/error call site. The error path keeps the explicit length guard; fixed-length parser branches rely on their existing length checks.Restored the original concise URN comment in
5055fd4.@ -87,10 +87,11 @@ impl<'a> InvalidUuid<'a> {return Error(ErrorKind::ParseChar { character, index });This method isn't
constso we can usebytes[..9].eq_ignore_ascii_case(..)@ -152,10 +152,15 @@ const fn try_parse(input: &'_ [u8]) -> Result<[u8; 16], InvalidUuid<'_>> {// - `{UUID}` for braced UUIDsNow that we've inlined the calls, I think this would now look better closer to your original formulation:
@ -87,10 +87,11 @@ impl<'a> InvalidUuid<'a> {return Error(ErrorKind::ParseChar { character, index });Updated this to use as suggested. Formatting and the full feature-matrix tests pass.
@ -152,10 +152,15 @@ const fn try_parse(input: &'_ [u8]) -> Result<[u8; 16], InvalidUuid<'_>> {// - `{UUID}` for braced UUIDsUpdated the 45-byte arm to split once and use the explicit if/else form from the suggestion. The no-default-features and all-features suites, UI tests, and doctests pass.
We can bump our MSRV to
1.89.0, it’s over 12 months old and not too far from our current one.@jaideeppyne Would you like a hand bumping our MSRV? It’s maintained in our GitHub Actions workflow, and as
rust-versionin ourCargo.toml. We just need to update those so we can use a few moreconstfeatures in this new code.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.