Skip to content

ec_semver:parse() incorrectly parsing "pre-release identifier" containing hyphen #144

@limeytexan

Description

@limeytexan

https://semver.org contains the following statement regarding the semantic version spec for "pre-release identifiers":

  1. A pre-release version MAY be denoted by appending a hyphen and a series of dot separated identifiers immediately following the patch version. Identifiers MUST comprise only ASCII alphanumerics and hyphen [0-9A-Za-z-]. Identifiers MUST NOT be empty. Numeric identifiers MUST NOT include leading zeroes. Pre-release versions have a lower precedence than the associated normal version. A pre-release version indicates that the version is unstable and might not satisfy the intended compatibility requirements as denoted by its associated normal version. Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7, 1.0.0-x.7.z.92.

Notably, ec_semver:parse() correctly parses all four of the above examples:

3> ec_semver:parse(<<"1.0.0-alpha">>).
{{1,0,0},{[<<"alpha">>],[]}}
4> ec_semver:parse(<<"1.0.0-alpha.1">>).
{{1,0,0},{[<<"alpha">>,1],[]}}
5> ec_semver:parse(<<"1.0.0-0.3.7">>).
{{1,0,0},{[<<"0">>,3,7],[]}}
6> ec_semver:parse(<<"1.0.0-x.7.z.92">>).
{{1,0,0},{[<<"x">>,7,<<"z">>,92],[]}}

However, a few [hex] packages contain hyphens in the "pre-release identifer" portion of the semantic version, e.g. https://hex.pm/packages/xclient/0.7.0-vendored-xhttp, and this breaks the parser:

7> ec_semver:parse(<<"0.7.0-vendored-xhttp">>).
{<<"0.7.0-vendored-xhttp">>,{[],[]}}

I've found that simply changing <<"[A-Za-z0-9]">> to <<"[A-Za-z0-9-]">> in src/ec_semver_parser.erl seems to address the problem, although I haven't reviewed the code sufficiently to say that this is the most appropriate fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions