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

"Pad" shorter versions with empty parts when comparing #5001

Merged
merged 7 commits into from
Nov 23, 2024

Conversation

Trenly
Copy link
Contributor

@Trenly Trenly commented Nov 22, 2024

When versions are created, any empty parts are trimmed off. This means that 22.0.0 is stored as [22] in memory. This causes an issue when comparing to a version that had additional parts, but should be sorted lower than the version which is trimmed, such as 22.0.0-rc. This is due to the comparator seeing that [22] has no more parts to compare after the first iteration, while [22, 0, 0-rc] does, causing it to hit the condition where whichever version has more parts is considered to be greater.

This PR updates the logic so that the version comparison effectively contains as many empty parts as are needed to fully complete the comparison. This retains the logic that if a part is not equal to the part it is being compared against, the result of that comparison will be returned but eliminates the need for checking if the versions have the same number of parts since, effectively, they do; it's just that the extra parts needed to complete the comparison are all empty.

Additional tests have been added to cover this corner case.

If possible, I would ask that this also be cherry-picked into any future 1.9 releases (assuming this PR passes review and merges)

Microsoft Reviewers: Open in CodeFlow

@Trenly Trenly requested a review from a team as a code owner November 22, 2024 18:29
@microsoft-github-policy-service microsoft-github-policy-service bot added the Issue-Bug It either shouldn't be doing this or needs an investigation. label Nov 22, 2024
florelis
florelis previously approved these changes Nov 22, 2024
src/AppInstallerCLITests/Versions.cpp Show resolved Hide resolved
@florelis
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Trenly Trenly requested a review from florelis November 22, 2024 21:25
florelis
florelis previously approved these changes Nov 22, 2024
@florelis
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Trenly
Copy link
Contributor Author

Trenly commented Nov 22, 2024

I'll get it right one of these times!

florelis
florelis previously approved these changes Nov 22, 2024
Copy link
Member

@florelis florelis left a comment

Choose a reason for hiding this comment

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

We should update the comment explaining the sorting

Copy link

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

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

🎉 Thanks for finding a fix so quickly.

I had one thought about some test cases to add, but I'm just commenting as an observer and my comments may not be aligned with the focus of the review.

src/AppInstallerCLITests/Versions.cpp Show resolved Hide resolved
@Trenly
Copy link
Contributor Author

Trenly commented Nov 23, 2024

We should update the comment explaining the sorting

Agreed and updated (and apologies for all the re-reviews @florelis!)

@florelis
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@florelis florelis merged commit 1deb4a8 into microsoft:master Nov 23, 2024
9 checks passed
@Trenly Trenly deleted the PadWhenComparing branch November 23, 2024 04:39
@Trenly
Copy link
Contributor Author

Trenly commented Nov 23, 2024

@florelis - Should I raise a cherry pick into 1.9, or has that next patch already been built?

@florelis
Copy link
Member

@florelis - Should I raise a cherry pick into 1.9, or has that next patch already been built?

Go ahead and create a PR for the cherry-pick. I'm fine with bringing the change to 1.9, but I'll leave the decision to @denelon / @JohnMcPMS

We haven't made a build with the latest changes, and most likely won't until after the holiday weekend.

Trenly added a commit to Trenly/winget-cli that referenced this pull request Nov 25, 2024
<!-- To check a checkbox place an "x" between the brackets. e.g: [x] -->

- [x] I have signed the [Contributor License
Agreement](https://cla.opensource.microsoft.com/microsoft/winget-pkgs).
- [x] This pull request is related to an issue.
  - Resolves microsoft#4998 

When versions are created, any empty parts are trimmed off. This means
that `22.0.0` is stored as `[22]` in memory. This causes an issue when
comparing to a version that had additional parts, but should be sorted
lower than the version which is trimmed, such as `22.0.0-rc`. This is
due to the comparator seeing that `[22]` has no more parts to compare
after the first iteration, while `[22, 0, 0-rc]` does, causing it to hit
the condition where whichever version has more parts is considered to be
greater.

This PR updates the logic so that the version comparison effectively
contains as many empty parts as are needed to fully complete the
comparison. This retains the logic that if a part is not equal to the
part it is being compared against, the result of that comparison will be
returned but eliminates the need for checking if the versions have the
same number of parts since, effectively, they do; it's just that the
extra parts needed to complete the comparison are all empty.

Additional tests have been added to cover this corner case.

If possible, I would ask that this also be cherry-picked into any future
1.9 releases (assuming this PR passes review and merges)
###### Microsoft Reviewers: [Open in
CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/microsoft/winget-cli/pull/5001)
Trenly added a commit to Trenly/winget-cli that referenced this pull request Nov 25, 2024
<!-- To check a checkbox place an "x" between the brackets. e.g: [x] -->

- [x] I have signed the [Contributor License
Agreement](https://cla.opensource.microsoft.com/microsoft/winget-pkgs).
- [x] This pull request is related to an issue.
  - Resolves microsoft#4998 

When versions are created, any empty parts are trimmed off. This means
that `22.0.0` is stored as `[22]` in memory. This causes an issue when
comparing to a version that had additional parts, but should be sorted
lower than the version which is trimmed, such as `22.0.0-rc`. This is
due to the comparator seeing that `[22]` has no more parts to compare
after the first iteration, while `[22, 0, 0-rc]` does, causing it to hit
the condition where whichever version has more parts is considered to be
greater.

This PR updates the logic so that the version comparison effectively
contains as many empty parts as are needed to fully complete the
comparison. This retains the logic that if a part is not equal to the
part it is being compared against, the result of that comparison will be
returned but eliminates the need for checking if the versions have the
same number of parts since, effectively, they do; it's just that the
extra parts needed to complete the comparison are all empty.

Additional tests have been added to cover this corner case.

If possible, I would ask that this also be cherry-picked into any future
1.9 releases (assuming this PR passes review and merges)
###### Microsoft Reviewers: [Open in
CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/microsoft/winget-cli/pull/5001)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error comparing versions
3 participants