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

Support version numbers lacking minor or patch parts #219

Closed
jszwedko opened this issue Nov 6, 2020 · 5 comments
Closed

Support version numbers lacking minor or patch parts #219

jszwedko opened this issue Nov 6, 2020 · 5 comments

Comments

@jszwedko
Copy link

jszwedko commented Nov 6, 2020

I'm interacting with an external system that returns version numbers lacking a patch part (like 2.1). I think it'd be fair to parse this as 2.1.0. Currently it rejects parsing with "expected more input". I'd similarly think that 2 could be parsed as 2.0.0.

I'm happy to take a stab at this in a PR, but wanted to get confirmation first given there are tests that are explicitly rejecting versions lacking minor or patch versions:

https://github.com/steveklabnik/semver/blob/051c39c50d565c597be65c4496597c7d16a514d9/src/version.rs#L399-L401

@porkbrain
Copy link

porkbrain commented Dec 9, 2020

This would be great. Could be hidden behind a feature not-strict or something like that? As an example from the wild: I use semver to serialize JSON from WP APIs. They just released a version 5.6, which means I cannot use this crate any more.

EDIT: There's the lenient_semver crate as an alternative to people who need to support semantic versions that don't adhere to the spec. Unfortunately the crates differ in APIs in at least two important ways:

@porkbrain
Copy link

porkbrain commented Dec 10, 2020

I forked this crate with just one change - support for versions 1 and 1.2, which default to 1.0.0 and 1.2.0 respectively. You can replace all semver:: with forgiving_semver:: and it should work out of the box. I am going to publish all new semver releases starting from version 0.11.0 until this crate supports a feature flag for forgiving parsing.

@sunshowers
Copy link

A feature flag is not the right way to do it, since features are unified across a build graph and other dependencies might expect strict version parsing.

(I don't think semver is the right place for this at all, to be honest. semver very specifically defines versions as having 3 components. A different crate like lenient_semver is the right approach.)

@dtolnay
Copy link
Owner

dtolnay commented May 25, 2021

I agree with #219 (comment) — I would prefer that these not parse.

I've updated the readme to indicate that if you are dealing with version numbers that are different from how Cargo interprets the SemVer spec, then this is not the crate you should be using.

@dtolnay dtolnay closed this as completed May 25, 2021
@theoparis
Copy link

theoparis commented Apr 4, 2023

A feature flag is not the right way to do it, since features are unified across a build graph and other dependencies might expect strict version parsing.

(I don't think semver is the right place for this at all, to be honest. semver very specifically defines versions as having 3 components. A different crate like lenient_semver is the right approach.)

This is unfortunate, as I am writing a package manager for my linux distribution and it seems like the alternative you mentioned is not maintained 😕

It seems like forgiving-semver isn't maintained either....

Repository owner locked and limited conversation to collaborators Apr 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants