Skip to content
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

Fix boost trac 8630, 9343, 11482, 11483, 12253 improving invalid string generator handling in uuid #17

Merged
merged 1 commit into from
Aug 9, 2017

Conversation

jeking3
Copy link
Collaborator

@jeking3 jeking3 commented Aug 3, 2017

For example, "12b672ea-388d-47da-9c26-bec5bc8a06cb-foo" was not considered invalid before, but it is now.

@eldiener
Copy link
Contributor

eldiener commented Aug 3, 2017

I would like to see tests for all 4 forms when generating from a string and there is unexpected extra data at the end of the string. Your test is good for 1 of the 4 different forms.

@jeking3 jeking3 changed the title 11482: fix uuid string generator handling of strings with garbage at the end Fix boost trac 11482, 11483, 12253 improving invalid string generator handling in uuid Aug 3, 2017
@jeking3 jeking3 changed the title Fix boost trac 11482, 11483, 12253 improving invalid string generator handling in uuid Fix boost trac 8630, 11482, 11483, 12253 improving invalid string generator handling in uuid Aug 4, 2017
@jeking3 jeking3 changed the title Fix boost trac 8630, 11482, 11483, 12253 improving invalid string generator handling in uuid Fix boost trac 8630, 9343, 11482, 11483, 12253 improving invalid string generator handling in uuid Aug 4, 2017
@jeking3
Copy link
Collaborator Author

jeking3 commented Aug 4, 2017

@eldiener I updated the pull request with the additional tests. If I can be of any assistance in grooming the boost trac backlog, let me know.

if (has_dashes) {
if (i == 6 || i == 8 || i == 10) {
// if there are dashes, they must be in every slot
if (i == 6 || i == 8 || i == 10) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this not be:
else if (i == 6 || i == 8 || i == 10) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can, I will push a change for it.

@@ -122,23 +133,27 @@ struct string_generator {
static char const*const digits_end = digits_begin + 22;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't your code but can't be take the sizeof(digits_begin) and use that instead of hardcoding 22 and further on down hardcoding '> 21' ? Hardcoding numbers is generally poor c++ if there is a better way to get the hardcoded value from the compiler.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sizeof(digits_begin) if changed to static wchar_t const digits_begin[] = ... is 46, confirmed by a BOOST_STATIC_ASSERT, so in this case I think the hardcoded values is appropriate. Considering the enhanced testing, any changes here will be caught.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the get_value(char c) case it should be:
sizeof(digits_begin)/sizeof(char)
and in the get_value(wchar_t c) case it should be:
sizeof(digits_begin)/sizeof(wchar_t)

so that hardcoded numbers are not used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, we'll have to subtract one, as the digits_end needs to point at the trailing NULL, but I will make this change.

@eldiener
Copy link
Contributor

eldiener commented Aug 9, 2017

The code works. Please see my comments for some possible individual changes.

I think the docs should be updated to both explain all the valid string formats uuid accepts and specifies that uuid throws a particular exception if the string is not a valid format or contains invalid hex digits.

@jeking3
Copy link
Collaborator Author

jeking3 commented Aug 9, 2017

I wonder if a boost::regex would be sufficient not only to describe the valid format but also enforce and to parse it, in the future. That would force a dependency that folks may not want however, and it may not be documentation-friendly.

@jeking3
Copy link
Collaborator Author

jeking3 commented Aug 9, 2017

I pushed an update that addresses all concerns thus far.

…put following successful conversion of a uuid in the input string

11483: uuid string generator now throws std::invalid_argument instead of std::runtime_error on an invalid uuid string
12253: make the uuid parser reject invalid data and added negative test cases to prove it
@eldiener eldiener merged commit 1061e09 into boostorg:develop Aug 9, 2017
@jeking3 jeking3 deleted the trac-11482 branch October 14, 2017 11:56
@jeking3 jeking3 self-assigned this Oct 18, 2017
@jeking3 jeking3 added the bug label Oct 18, 2017
@jeking3 jeking3 added this to the v1.66.0 milestone Oct 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants