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

Modify StringToken::PATTERN to fix comparison #8125

Merged
merged 1 commit into from Jul 29, 2020
Merged

Modify StringToken::PATTERN to fix comparison #8125

merged 1 commit into from Jul 29, 2020

Conversation

samford
Copy link
Member

@samford samford commented Jul 28, 2020

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew tests with your changes locally?

StringToken's PATTERN regex (/[a-z]+[0-9]*/i) is consuming numeric parts of the version string that should probably be tokenized separately as a NumericToken. As a result, you can end up with incorrect version comparisons when part of the version string consists of letters with trailing numbers.

Taking Homebrew/homebrew-core#58711 as an example, 4.0ga10 is treated as older than 4.0ga9. This is because 4.0ga10 is currently tokenized as follows:

[#<Version::NumericToken 4>,
 #<Version::NumericToken 0>,
 #<Version::StringToken "ga10">]

When ga10 is compared to ga9 (i.e., "ga10" <=> "ga9"), it's reported as being lower (-1). To address this, we can compare ga and 10/9 separately (as a StringToken and NumericToken respectively).


This PR removes the [0-9]* from StringToken's PATTERN regex, which results in the aforementioned version being tokenized as follows:

[#<Version::NumericToken 4>,
 #<Version::NumericToken 0>,
 #<Version::StringToken "ga">,
 #<Version::NumericToken 10>]

This produces the comparison result that we would expect, where 4.0ga10 is treated as newer than 4.0ga9.

I did a full livecheck run over the homebrew-core formulae with/without the change in this PR and the only difference was with x3270. At least from the perspective of livecheck, this change doesn't seem to result in any undesirable version comparison issues.


I've left this as a draft for the moment because I have a question about how we should be doing StringToken comparisons. It seems like we should treat ga and GA as the same, otherwise 4.0ga10 would be treated as newer than 4.0GA11. To address this, we would seemingly need to modify StringToken comparisons to ignore case.

Is anyone aware of any situations where letter case is used to indicate something newer (e.g., cycling through lowercase a-z before proceeding to uppercase A-Z)? Once we've decided how to proceed in this area, I'll add some additional tests and mark this as ready for review.

@MikeMcQuaid MikeMcQuaid marked this pull request as ready for review July 29, 2020 10:27
@MikeMcQuaid
Copy link
Member

This makes sense to me. Merging as-is because it's fixing a user issue and the rest can be tackled in a future PR. Thanks @samford, great work!

@MikeMcQuaid MikeMcQuaid merged commit a7e9b47 into Homebrew:master Jul 29, 2020
@samford samford deleted the modify-stringtoken-pattern branch July 29, 2020 13:14
@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Dec 21, 2020
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Dec 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants