Skip to content

Using x in prerelease causes error #75

@danielhelfand

Description

@danielhelfand

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions