feat: Validate UUID without creating new UUID#141
Merged
bormanp merged 2 commits intogoogle:masterfrom Dec 12, 2023
Merged
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
0d6d439 to
3394eb7
Compare
bormanp
suggested changes
Dec 11, 2023
Contributor
bormanp
left a comment
There was a problem hiding this comment.
Only the comment needs fixing.
uuid.go
Outdated
| return uuid | ||
| } | ||
|
|
||
| // Validate checks if the input string is a properly formatted UUID in various recognized formats. |
Contributor
There was a problem hiding this comment.
// Validate returns an error if s is not a properly formatted UUID in one of the following formats:
// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
bormanp
approved these changes
Dec 12, 2023
hslatman
added a commit
to smallstep/cli
that referenced
this pull request
Dec 19, 2023
In google/uuid#141 a new `Validate` function was added to the `uuid` package. This can be used when no UUID struct is required, so can be used instead of `Parse`. This takes #1087, but uses `uuid.Validate` in one location.
tkarrass
pushed a commit
to tkarrass/uuid
that referenced
this pull request
Sep 11, 2024
* feat: Validate UUID without creating new UUID * fix: update comment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This pull request introduces a new function,
Validate(s string) error, in response to the request in issue #137. The primary goal is to provide a way to validate UUID strings without the overhead of creating a UUID object and its underlying byte array, as currently happens in theParse(s string) (UUID, error)function.Changes Made
Validate(s string) errorwhich checks the format of the UUID string without generating a UUID object.Rationale
This change is particularly useful in scenarios where UUIDs are frequently validated but not used in their byte form. It optimizes performance by eliminating unnecessary memory allocations associated with UUID object creation, especially in high-throughput environments.
Testing
Unit tests have been added to cover various cases:
The tests ensure that the new validation function behaves as expected across a wide range of valid and invalid inputs.
Impact
This update introduces a non-breaking change, adding new functionality to the library without altering existing behaviors.
Looking forward to your feedback and suggestions on this implementation!
Resolves #137