Skip to content

Distinguish between zero values and missing values #175

@mcandre

Description

@mcandre

I have a need to distinguish between "2" and "2.0" post-parsing, without having to re-parse these strings.

For example, I am writing an automated system to identify when software component versions are no longer supported. The data about support timelines can vary about specificity, so that some products exit support as of a major-wide series 2.x ("2"), whereas other products develop at a much faster rate and can exit support as of particular minor versions ("2.0").

Unfortunately, it appears that semver simply defaults unspecified minor version values, etc. etc. as zero, without providing a clear way to distinguish between an explicit zero input, versus an implicit default of missing information to zero.

I think I may hack around this gap by counting the periods in the original version string prior to parsing with semver. But I would love for a standard feature such as HasMinor(), HasPatch(), HasBuild(), to clarify in a reliable way.

Activity

mattfarina

mattfarina commented on Aug 15, 2022

@mattfarina
Member

It's been a little bit since you posted this so may already have a setup that works for this.

When it comes to versions, a missing section is a 0. When an x is used it's a range and that means a constraint. Versions are covered by the semver spec while constraints used for things like ranges are made up by implementers. Some of use try to follow the same patterns.

The way to do all of that with this library is to parse your version as a version (e.g., 2.0.0), create a constraint (e.g., =2.0.0 or 2.x), and then test the version against the constraint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Distinguish between zero values and missing values · Issue #175 · Masterminds/semver