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 comparison issues #11

Merged
merged 2 commits into from
Oct 30, 2023

Conversation

chriseplettsonos
Copy link
Contributor

@chriseplettsonos chriseplettsonos commented Jun 12, 2023

As implemented, there were a couple of problems where the library was not performing comparisons between semvers correctly.

The first issue is that the presence of buildmetadata was causing the library to treat the version as unstable, which also meant that, given the comparison implementation, the buildmetadata was being considered when comparing two semvers. This is a violation of Section 10 of the semver.org spec, which specifies that “Build metadata MUST be ignored when determining version precedence”. Additionally, it is not specified by semver.org that that the presence of buildmetadata should be involved in determining the stability of a semver. Only the presence of pre-release should be used to determine the stability of the version.

The second problem is that the library uses simple ASCII lexical ordering to compare the pre-release string of two semvers, which does not match the rules defined in Section 11.4 of the semver specification.

This change addresses these problems with the following changes

  1. Remove the build.isEmpty check from the implementation of the isStable property
  2. Implement a PreReleaseIdentifier enum and add Comparable conformance to an array of these types, per the rules laid out in Section 11.4 of the semver specification
  3. Add a computed property that returns an array of PreReleaseIndentifiers by parsing the preRelease string
  4. Update the less than operator implementation to apply the above changes appropriately
  5. Add additional test cases to verify the new behavior

Testing:

  • Existing unit tests pass
  • New unit tests pass

@cla-bot
Copy link

cla-bot bot commented Jun 12, 2023

Thanks so much for submitting a pull request. We appreciate your contribution!

We require all contributors to sign our Contributor License Agreement (CLA) before we can merge any code, and we don't currently have a record of a signed CLA for @chriseplettsonos. Please email [email protected] and let us know you need to sign a CLA, and we'll get the template over to you.

1 similar comment
@cla-bot
Copy link

cla-bot bot commented Jun 12, 2023

Thanks so much for submitting a pull request. We appreciate your contribution!

We require all contributors to sign our Contributor License Agreement (CLA) before we can merge any code, and we don't currently have a record of a signed CLA for @chriseplettsonos. Please email [email protected] and let us know you need to sign a CLA, and we'll get the template over to you.

Copy link
Member

@finestructure finestructure left a comment

Choose a reason for hiding this comment

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

This is great, thanks for the contribution, @chriseplettsonos !

We'll merge this once the CLA is in place.

@chriseplettsonos
Copy link
Contributor Author

chriseplettsonos commented Jun 27, 2023 via email

@daveverwer
Copy link
Member

You should have received a signed CLA for this on or around 21-Jun. Did that come through?

Hey Chris. Yes, but there was some information missing. I CCed you on the reply I sent asking for the additional information. I'll drop you another email now.

@finestructure
Copy link
Member

Fixes #14

@daveverwer
Copy link
Member

@cla-bot check

@cla-bot cla-bot bot added the cla-signed label Sep 22, 2023
@cla-bot
Copy link

cla-bot bot commented Sep 22, 2023

The cla-bot has been summoned, and re-checked this pull request!

As implemented, there were a couple of problems where the library was not performing comparisons between semvers correctly.

The first issue is that the presence of buildmetadata was causing the library to treat the version as unstable, which also meant that, given the comparison implementation, the buildmetadata was being considered when comparing two semvers. This is a violation of Section 10 of the semver.org spec, which specifies that “Build metadata MUST be ignored when determining version precedence”. Additionally, it is not specified by semver.org that that the presence of buildmetadata should be involved in determining the stability of a semver.

The second problem is that the library uses simple ASCII lexical ordering to compare the pre-release string of two semvers, which does not match the rules defined in Section 11.4 of the semver specification.

This change addresses these problems with the following changes
1) Remove the build.isEmpty check from the implementation of the isStable property
2) Implement a PreReleaseIdentifier enum and add Comparable conformance to an array of these types, per the rules laid out in Section 11.4 of the semver specification
3) Add a computed property that returns an array of PreReleaseIndentifiers by parsing the preRelease string
4) Update the less than operator implementation to apply the above changes appropriately
5) Add additional test cases to verify the new behavior

Testing:
1) Existing unit tests pass
2) New unit tests pass
@chriseplettsonos
Copy link
Contributor Author

@finestructure Just curious if this (and my other PR) might be merged soon? If not, we can continue working off of our fork, but I'd love to see these changes released.

Thanks! - Chris E.

@finestructure
Copy link
Member

Apologies @chriseplettsonos , this had completely fallen off my radar. Thanks for the ping!

@finestructure
Copy link
Member

Just noticed the CodeQL failure

CodeQL detected code written in Swift but could not process any of it. Review our troubleshooting guide at https://gh.io/troubleshooting-code-scanning/no-source-code-seen-during-build.

Ignoring that.

@finestructure finestructure merged commit d148d8e into SwiftPackageIndex:main Oct 30, 2023
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants