Skip to content

validRange doesn't format x-ranges correctly #183

Closed

Description

@alkhe

Currently semver.validRange doesn't correctly format unions containing full x-ranges.

validRange('*') // good: '*'
validRange('* || 1.0.0') // bad: '||1.0.0'
validRange('* || *') // bad: '||'

I would recommend simply returning '*' if any of the components are '*', like such:

validRange('*') // '*'
validRange('* || 1.0.0') // '*'
validRange('* || *') // '*'

relevant code:
semver.js#L709
semver.js#L1107

Activity

  1. changed the title [-]validRange doesn't format asterisks correctly[/-] [+]validRange doesn't format x-ranges correctly[/+] on Jan 27, 2017
  2. isaacs commented on Jan 30, 2017

    @isaacs
    Contributor

    But those aren't actually identical.

    I would recommend simply returning * if any of the components are *, like such:

    Consider that * doesn't match (by design) 1.0.0-prerelease. So, * || 1.0.0-prerelease is different than *.

    validRange('* || 1.0.0') // bad: '||1.0.0'

    Since a blank range is equivalent to *, ||1.0.0-prerelease actually is identical to * || 1.0.0-prerelease.

    I agree that it would be nice to omit identical ranges that exist between || characters. Thus *||* would reduce to || and then merely a blank line, which would be replaced by * (which is there to support checks that do if(validRange(...)) and expect null to be the only non-truthy return value). We could also remove ranges in the set that don't have any prerelease parts if there's a *. Patches welcome for those enhancements.

    But what's there now is not semantically incorrect, and is working as intended.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions