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

Using x in prerelease causes error #75

Open
danielhelfand opened this issue Nov 29, 2021 · 0 comments · May be fixed by #76
Open

Using x in prerelease causes error #75

danielhelfand opened this issue Nov 29, 2021 · 0 comments · May be fixed by #76

Comments

@danielhelfand
Copy link

Given the version 0.1.0-x, ParseRange returns the following error:

Could not get version from string: "<"

Replacing the x with another character fixes the problem (e.g. 0.1.0-y).

This appears to be related to x being used to denote wildcards as implemented in #27:

if strings.Contains(ap, "x") {

This can be reproduced with the following test:

func TestExpandWildcardVersion(t *testing.T) {
	tests := []struct {
		i [][]string
		o [][]string
	}{
		{[][]string{{"foox"}}, nil},

                // FAILING TEST
		{[][]string{{"0.1.0-x"}}, [][]string{{"0.1.0-x"}}},


		{[][]string{{">=1.2.x"}}, [][]string{{">=1.2.0"}}},
		{[][]string{{"<=1.2.x"}}, [][]string{{"<1.3.0"}}},
		{[][]string{{">1.2.x"}}, [][]string{{">=1.3.0"}}},
		{[][]string{{"<1.2.x"}}, [][]string{{"<1.2.0"}}},
		{[][]string{{"!=1.2.x"}}, [][]string{{"<1.2.0", ">=1.3.0"}}},
		{[][]string{{">=1.x"}}, [][]string{{">=1.0.0"}}},
		{[][]string{{"<=1.x"}}, [][]string{{"<2.0.0"}}},
		{[][]string{{">1.x"}}, [][]string{{">=2.0.0"}}},
		{[][]string{{"<1.x"}}, [][]string{{"<1.0.0"}}},
		{[][]string{{"!=1.x"}}, [][]string{{"<1.0.0", ">=2.0.0"}}},
		{[][]string{{"1.2.x"}}, [][]string{{">=1.2.0", "<1.3.0"}}},
		{[][]string{{"1.x"}}, [][]string{{">=1.0.0", "<2.0.0"}}},

	}

	for _, tc := range tests {
		o, _ := expandWildcardVersion(tc.i)
		if !reflect.DeepEqual(tc.o, o) {
			t.Errorf("Invalid for case %q: Expected %q, got: %q", tc.i, tc.o, o)
		}
	}
}

Result of this test is: Invalid for case [["0.1.0-x"]]: Expected [["0.1.0-x"]], got: [[">=0.1.0-x" "<"]]

At the very least, it would be helpful to call out this corner case in the docs if fixing this would be challenging due to breaking changes.

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

Successfully merging a pull request may close this issue.

1 participant