WalkerCodeRanger/semver

Prevent Inverted SemVersionRange Values ("1.2 - 1.0")

Closed this issue · 2 comments

The SemVersionRange.TryParseNpm methods will return true if you pass inverted version ranges.

Example

Imagine that you are trying to check if a version range is a valid version range. You can create code similar to the following:

public static bool IsValidRange(string range) {
    return SemVersionRange.TryParseNpm(range, out _);
}

When passing 1.2 - 1.0 for range, this method returns true. However, I thought that it would return false. I think that 1.2 - 1.0 isn't a valid version range for NPM.

I believe 1.2 - 1.0 is a valid but empty range according to npm. You can see this easily using https://semver.npmjs.com/

I understand why it feels like it might be invalid, but according to the official npm, which TryParseNpm is trying to match, it is.

I believe 1.2 - 1.0 is a valid but empty range according to npm. You can see this easily using https://semver.npmjs.com/

I understand why it feels like it might be invalid, but according to the official npm, which TryParseNpm is trying to match, it is.

@WalkerCodeRanger - Apologies for reporting something that isn't an issue. Thanks for looking into this.