Skip to content

Version parsing from namespace bug fix #366

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

Closed
wants to merge 1 commit into from
Closed

Version parsing from namespace bug fix #366

wants to merge 1 commit into from

Conversation

dlyz
Copy link

@dlyz dlyz commented Oct 11, 2018

When some controller namespace contains segment starting with v, and the next segment contains actual version, then VersionByNamespaceConvention skips second segment due to dividing dot capture.

For example version parsing fails with namespace VersioningSample.V1.Controllers.

This fix uses regex lookahead on trailing dot.

@msftclas
Copy link

msftclas commented Oct 11, 2018

CLA assistant check
All CLA requirements met.

@@ -23,7 +23,7 @@ static string GetRawApiVersion( string @namespace )

// 'v' | 'V' : [<year> '-' <month> '-' <day>] : [<major[.minor]>] : [<status>]
// ex: v2018_04_01_1_1_Beta
const string Pattern = @"(?:^|\.)[vV](\d{4})?_?(\d{2})?_?(\d{2})?_?(\d+)?_?(\d*)_?([a-zA-Z][a-zA-Z0-9]*)?(?:$|\.)";
const string Pattern = @"(?:^|\.)[vV](\d{4})?_?(\d{2})?_?(\d{2})?_?(\d+)?_?(\d*)_?([a-zA-Z][a-zA-Z0-9]*)?(?=($|\.))";
Copy link
Collaborator

Choose a reason for hiding this comment

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

While it seems this pattern works, I'm not sure this is the full solution. This change only switches from a non-capture to a look-ahead captured as a group.

Alternative 1

I believe the fix can simply be done by requiring the status to have a leading _ as in:

(?:^|\.)[vV](\d{4})?_?(\d{2})?_?(\d{2})?_?(\d+)?_?(\d*)(_([a-zA-Z][a-zA-Z0-9]*))?(?:$|\.)

Alternative 2

The pattern can be more flexible to not require the leading _, but things get a lot uglier:

(?:^|\.)[vV]((\d{4})_?(\d{2})_?(\d{2})_?(\d+)_?(\d*)|(\d{4})_?(\d{2})_?(\d{2})|(\d+)_?(\d*))_?([a-zA-Z][a-zA-Z0-9]*)?(?:$|\.)

This would be the most flexible and comprehensive solution. Everything after v must be either date, major, and minor, date, or major and minor. Then, and only then, can it be followed by a status. The existing pattern is wrong because it ends up capturing ersioningSample as a status which isn't even valid by itself.

Conclusion

Either of these options will require some small amount of code changes because the grouping also changes.

@commonsensesoftware
Copy link
Collaborator

I've actually gone ahead and fixed the issue separately in #377, but referenced your PR. The final pattern change just needed to be a set rather than a non-capture group. I added your example to the test suite to prevent future regressions. Thanks for not only reporting the issue, but taking the time to try and fix it. It's appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants