-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Adds UUID Support #989
Adds UUID Support #989
Conversation
I added proper bracket support, bracket/separator match support and support for options in the form of Help with testing would be appreciated! Thanks! |
In your tests, did you generate those UUIDs or copy a single one and modify its versioning? This comes up because doing so means you may be validating out-of-spec UUIDs (Mostly thinking about v1 and v2 since they rely on semi-fixed seed data). |
From what I'm seeing within RFC 4122 it wouldn't matter how these are generated as they all validate to the same style (with the exception of the version number). Here's the ABNF from page 4:
Based on that document the validation of the output doesn't change from what I'm seeing but how that output is generated (ie. with MAC address, timestamps, etc.) is what changes. They still come out to the same format (with the exception of the version number). |
} | ||
|
||
// Matching braces | ||
if (brackets[results[1]] !== results[11]) { |
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'm not sure if they are eluding me or what but I'm not seeing any tests for mismatched braces.
} | ||
|
||
return this.createError('string.guid', { value }, state, options); | ||
// Matching separators | ||
if (results[3] !== results[5] || results[3] !== results[7] || results[3] !== results[9]) { |
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 wasn't able to find any tests for mismatches separators (not sure if they are hiding from me).
@@ -2983,7 +2983,74 @@ describe('string', () => { | |||
['b4b2fb69c6244e5eb0698e0c6ec66618', true], | |||
['{283B67B2-430F-4E6F-97E6-19041992-C1B0}', false, null, '"value" must be a valid GUID'], | |||
['{D1A5279D-B27D-4CD4-A05E-EFDD53D08E8D', false, null, '"value" must be a valid GUID'], | |||
['D1A5279D-B27D-4CD4-A05E-EFDD53D08E8D}', false, null, '"value" must be a valid GUID'] | |||
['D1A5279D-B27D-4CD4-A05E-EFDD53D08E8D}', false, null, '"value" must be a valid GUID'], |
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.
These are the tests I added for mismatched braces and separators.
The existing test above this (line 2985) is also a test for that.
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.
Do you have tests for hyphenated UUIDs without brackets? These are technically valid also, though they require all hyphens to be included.
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.
Sorry, @kamronbatman I was meaning ones like [D1A5279D-B27D-4CD4-A05E-EFDD53D08E8D}
where the braces don't match. I definitely saw the ones your referenced above.
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.
@gelliott181 There is already a test for that: line 2978. I could add them to each of the UUID versions, but it would technically be duplicative because of how the code is written. Let me know what you think.
@DavidTPate I see what you are saying. I can definitely add them in but based on how the code was written it is duplicatable. No brackets mixed with brackets are considered the same as mixing other types of brackets (parenths, braces, etc).
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 would expect the tests to verify that the functionality is working as expected, not that the code is working the way it was written.
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.
Ok, fair enough.
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.
@gelliott181 and @DavidTPate I updated/added more tests. Let me know what you two think.
Thanks!
LGTM |
@DavidTPate I added support for string value of the versions option. Also updated the API reference. |
@Marsup I think this might be ready to merge! 🎉 |
@DavidTPate @gelliott181 and @Marsup - I updated the options, added assertions, and segregated the tests to follow in the way other Joi features were written. Should still be good in terms of tests/coverage. |
versions = Hoek.unique(versions); | ||
} | ||
|
||
const regex = /^([\[{\(]?)([0-9A-F]{8})([:-]?)([0-9A-F]{4})([:-]?)([0-9A-F]{4})([:-]?)([0-9A-F]{4})([:-]?)([0-9A-F]{12})([\]}\)]?)$/i; | ||
|
||
return this._test('guid', undefined, function (value, state, options) { |
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.
Please add the options here instead of leaving undefined
.
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 think I fixed it appropriately. Let me know.
'uuidv5': '5' | ||
}; | ||
|
||
let versions; |
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'd rather have a const here and check for length later.
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 was following line 186. Not sure what you would suggest otherwise.
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.
Oh I see, I guess the code can't always be consistent everywhere :)
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.
ok, so are you thinking to move the checks to inside of the test callback? I am sorry for being confused on your thoughts.
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 was suggesting a const versions = []
, but I guess we won't be able to do the unique then, I don't think it matters much.
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 think I changed it to what you were asking. Let me know if that works and I will resquash.
Are you able to squash all those commits as well ? |
I just squashed it. And yes, I did not make a const because of the unique check. |
@Marsup Not sure if you know about it or just prefer it be done differently but wanted to point out that you can now squash on merge for a PR in GitHub (you can also rebase too as of this week prior to merge). You can see the announcement for more details. |
I know about it, they did it wrong. I want squashed commits but I still want the merge commit, none of the options work for me. |
Roger that, @Marsup it definitely doesn't add a merge commit like you point out. Just wanted to see if it would work for you. |
Thanks a lot for the work y'all, I'll release in a bit as I need to add another small thing to it. |
Nice PR @kamronbatman, thanks for taking my minor change so much further! |
Adds UUID version 1 through 5 support. Based on #970.