Unit test - more strict format string#6
Conversation
Changes: * hex digit character class * more strict rfc4122 compliance for variant
This fixes the code to be spec-compliant. Specifically: * reserved NCS variant must have bit 7 cleared * reserved RFC 4122 must have bit 7 set and bit 6 cleared * reserved microsoft must have bits 6 and 7 set and bit 6 cleared The code happened to be doing exactly the opposite. There might be a more elegant way of doing this though. http://www.ietf.org/rfc/rfc4122.txt
|
This happens to fix #2 by accident. Let me know if you'd like me to rebase. |
There was a problem hiding this comment.
These changes do exactly the same job, in a more unreadable way.
|
Simple counter example for v4 uuids (generated from your uuid package): c73d8f33-f7f8-4b84-626c-022ea05dd742 Code: From Wikipedia:
As you can see, byte 8 in the result above is 6, which is not one of 8, 9, a or b. Wikipedia is consistent with the spec: So, a compliant byte 8 looks like this (x is placeholder): So, the top 4 bits would be one of:
The existing code does this: This will set the second msb and do a bitwise and on
If you run the code a few times, you should be able to see the pattern. I fixed the regex in the test file, and that may make things a bit more clear. The old regex was a bit too open in what it accepted. If you want me to revise my PR to exclude kisielk's commits, I can do that. I wasn't sure if you abandoned this repo since there hasn't been a commit for a year or so, so I went ahead and pulled in his changes. I suppose you could also fix the code by doing something like this (for RFC4122): I just did a literal translation of the spec, hence the relatively clumsy syntax. I'd be happy to throw together another PR if you want the change. |
Changes:
This depends on #6 to be merged in order to pass.