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 for numeric only release labels with floating ranges #1601

Merged
merged 1 commit into from Aug 2, 2017

Conversation

emgarten
Copy link
Member

@emgarten emgarten commented Aug 1, 2017

  • Allow 1.0.0-* to float from 1.0.0-0 instead of 1.0.0-- which is a non-numeric label.
  • Treat floating labels that end with . in the same way as labels ending in - when converting to non-snapshot versions for display purposes.

For alpha-numeric labels in SemVer - is the lowest possible label in lexicographical order. In SemVer 2.0.0 numeric labels are lower than alpha-numeric labels per the rules, which puts 0 before - despite the lexicographical order.

When converting 1.0.0-* to the min version of range a release label is needed to avoid ending up with 1.0.0 which is stable. To handle this NuGet adds the lowest possible release label as a place holder, previously it was incorrectly using -, now it will use 0 only when the label is empty.

This extra label is primarily an internal thing, when displayed to users it is removed using ToNonSnapshotVersion, the result of which is only for display, it isn't used for comparing versions.

I've added more tests for this, and there are quite a few existing tests around this already verifying that the behavior is the same.

Fixes NuGet/Home#4513

* Allow 1.0.0-* to float from 1.0.0-0 instead of 1.0.0-- which is a non-numeric label.
* Treat floating labels that end with . in the same way as labels ending in - when converting to non-snapshot versions for display purposes.

Fixes NuGet/Home#4513
Copy link
Contributor

@mishra14 mishra14 left a comment

Choose a reason for hiding this comment

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

Small requests. But looks fine other wise.

get { return _minVersion != null; }
}

public bool HasMinVersion => _minVersion != null;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -202,17 +197,16 @@ public static bool TryParse(string versionString, out FloatRange range)
{
releasePrefix = actualVersion.Substring(versionString.LastIndexOf('-') + 1);

if (actualVersion.EndsWith("-"))
// For numeric labels 0 is the lowest. For alpha-numeric - is the lowest.
if (releasePrefix.Length == 0 || actualVersion.EndsWith("."))
Copy link
Contributor

Choose a reason for hiding this comment

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

The previous code had a comment around actualVersion.EndsWith(".") - // TODO: Solve this better.

Have we addressed that? If not then we should leave the comment there.

Copy link
Member Author

@emgarten emgarten Aug 1, 2017

Choose a reason for hiding this comment

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

I would say it is solved, it was probably due to speculation that a bug like that one fixed here could exist. SemVer 2.0.0 was very new at that time.

{
// Remove the - for 1.0.0-* (1.0.0--)
fixedReleaseLabel = lastLabel.Substring(0, lastLabel.Length - 1);
if (lastLabel.EndsWith("--", StringComparison.Ordinal))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be simplified as -

                    // Remove the - for 1.0.0-* (1.0.0--)
                    var charsToRemove = 1;
                    if (lastLabel.EndsWith("--", StringComparison.Ordinal))
                    {
                        // For labels such as rc1-* an additional - is added by nuget
                        charsToRemove = 2;
                    }
                    fixedReleaseLabel = lastLabel.Substring(0, lastLabel.Length - charsToRemove);

Copy link
Member Author

@emgarten emgarten Aug 1, 2017

Choose a reason for hiding this comment

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

that is more compact, do you think the flow/intent is as obvious there?

Copy link
Contributor

Choose a reason for hiding this comment

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

I personally like that style. it implies that we have a default behavior which is over written in some cases. Your call! :)

Copy link
Member Author

@emgarten emgarten Aug 2, 2017

Choose a reason for hiding this comment

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

Normally I'd agree, but here the default behavior is to do nothing. Two special cases exists where extra truncation is needed. Appreciate the extra feedback on it though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants