Coder Social home page Coder Social logo

Parsing "1.0" returns an error about semver HOT 15 CLOSED

blang avatar blang commented on June 26, 2024
Parsing "1.0" returns an error

from semver.

Comments (15)

blang avatar blang commented on June 26, 2024 1

Yap, you're right but i don't think simply accepting such "wrong" versions would be an option. Maybe i could introduce a ParseTolerant method which converts such versions to valid semvers. I will think about it.
Feel free to fork :)

from semver.

kujenga avatar kujenga commented on June 26, 2024 1

Great! Just submitted PR #19

from semver.

awakia avatar awakia commented on June 26, 2024 1

Hi, I had same problem. Thank you for fixing this issue.
However, the PR implementation seems wrong to me.

Version "1.0" generally means latest version of "1.0.x", not "1.0.0". So, why don't you parse "1.0" as "1.0.INT_MAX"?

from semver.

kujenga avatar kujenga commented on June 26, 2024 1

@awakia That's a fair point! I think the reason I didn't go that route was that serializing versions was a concern for my use case, and 1.0.9223372036854775807 looks a bit funky.

Since we almost certainly don't want to change the underlying data structure, one way to go would be changing the String() function here to wrap the appends of extra version parameters like so:

// Version to string
func (v Version) String() string {
    b := make([]byte, 0, 5)
    b = strconv.AppendUint(b, v.Major, 10)
     if v.Minor != math.MaxUint64 {
        b = append(b, '.')
        b = strconv.AppendUint(b, v.Minor, 10)
    }
    if v.Patch != math.MaxUint64 {
        b = append(b, '.')
        b = strconv.AppendUint(b, v.Patch, 10)
    }

    // ...

This would maintain readability of the stringified versions. @blang what do you think?

from semver.

blang avatar blang commented on June 26, 2024 1

I think 1.0 is more like a range >0.9 <1.1 than a concrete version, but in case of a version i think 1.0 should be 1.0.0. Using something like 1.0.MAX would also imply: 1.0.0 < 1.0 and 1.0.0 != 1.0 which is counter intuitive imo.
Changing the String() method would also break the spec kinda, that's a no-no.
But you might think about extending the range code, something like Return the last version included in the given range

from semver.

blang avatar blang commented on June 26, 2024

Yes, that's intended, because of the semver spec:
2. A normal version number MUST take the form X.Y.Z where X, Y, and Z are non-negative integers[..]

"1.0" is not valid semver version, but "1.0.0" is.

from semver.

blang avatar blang commented on June 26, 2024

Oh did you edit your question or did i read wrong?
Since that is a semver library only, it would be spec breaking if i would allow "1.0" as a valid version.

from semver.

vmihailenco avatar vmihailenco commented on June 26, 2024

I added last sentence by editing the question (though before I saw your answer).

I will have to fork your lib, because all the world uses versions like "v1.0" and thinks that it is semver format. E.g. gopkg.in supports both v3, v3.N, or v3.N.M format.

from semver.

cbandy avatar cbandy commented on June 26, 2024

I don't see anything on gopkg.in that claims anything about semantic versioning (as described by semver.org.) I think the part you referenced, @vmihailenco, is about "selectors."

When using branches or tags to version the GitHub repository, gopkg.in understands that a selector in the URL such as "v1" may be satisfied by a tag or branch "v1.2" or "v1.2.1" (vMAJOR[.MINOR[.PATCH]]) in the repository, and will select the highest version satisfying the requested selector.

from semver.

cbandy avatar cbandy commented on June 26, 2024

See semver/semver#237

from semver.

vmihailenco avatar vmihailenco commented on June 26, 2024

Thanks for the link. I am not going to argue about semver spec. I just think that v1 (or v1.0) is not any worse than v1.0.0 and I want to accept it as user input. And I don't see any complications for parser to support such format.

from semver.

blang avatar blang commented on June 26, 2024

I still think this repo should remain strict semver spec only, but i also think it would be a nice addition to support parsing other version variants (v1.0, 1.0, ..) in a separate library and build proper semvers out of it. Anyone interested in contributing?

from semver.

kujenga avatar kujenga commented on June 26, 2024

@blang Would you be open to adding the ParseTolerant function you mentioned above if it was submitted in a PR?

from semver.

blang avatar blang commented on June 26, 2024

I guess that depends on the extend of this function. I think there is a lot of room for convenience beginning at a starting 'v' and ending up trimming spaces, removing quotes etc. If it's a small function with a limited scope and useful for most usecases i would be glad if someone could make this happen.
I think it should be fully decoupled and only preparing the version string before feeding it to Parse.

from semver.

blang avatar blang commented on June 26, 2024

Thank you

from semver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.