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

Fix declare() with dash and extra #10

Closed
wants to merge 1 commit into from

Conversation

andrewalker
Copy link

SemVer has a bug introduced in 8781c0d:

$ perl -MSemVer -le'print SemVer->declare("3.1.0")->normal'
3.1.0
$ perl -MSemVer -le'print SemVer->declare("3.1.0-something")->normal'
Invalid version format (version required) at .../SemVer.pm line 90.

What happens in the second case ("3.1.0-something") is that this regular
expression matches:

  (my $v = $ival) =~ s/^v?$STRICT_DOTTED_INTEGER_VERSION(?:($DASH_SEPARATOR)($OPTIONAL_EXTRA_PART))[[:space:]]*$//;

So the entire version string is replaced by nothing, and that is the
value that $v gets. All other cases (such as "3.1", or "3.1.0") don't
match, and so the replacement never happens.

This empty $v is then passed on to version->declare, which complains
that the version is required.

It seems the full regexp was added hoping to be a validation step for
strict semantic versions in declare() and parse(). Unfortunately, this
wasn't working (as explained above), and in fact, that is not the
desired behaviour for these functions. From the docs for declare():
"This is the most flexible way to declare versions. Consider using it to
normalize version strings." With that in mind, the input has to allow
"not normal" version strings.

This patch restores the old behaviour, fixing usage of declare() and
parse(). I'm not super comfortable with how parse() is supposed to work,
so I didn't add any tests for it. But I did add tests for declare().

SemVer has a bug introduced in 8781c0d:

  $ perl -MSemVer -le'print SemVer->declare("3.1.0")->normal'
  3.1.0

  $ perl -MSemVer -le'print SemVer->declare("3.1.0-something")->normal'
  Invalid version format (version required) at .../SemVer.pm line 90.

What happens in the second case ("3.1.0-something") is that this regular
expression matches:

  (my $v = $ival) =~ s/^v?$STRICT_DOTTED_INTEGER_VERSION(?:($DASH_SEPARATOR)($OPTIONAL_EXTRA_PART))[[:space:]]*$//;

So the entire version string is replaced by nothing, and that is the
value that $v gets. All other cases (such as "3.1", or "3.1.0") don't
match, and so the replacement never happens.

This empty $v is then passed on to version->declare, which complains
that the version is required.

It seems the full regexp was added hoping to be a validation step for
strict semantic versions in declare() and parse(). Unfortunately, this
wasn't working (as explained above), and in fact, that is not the
desired behaviour for these functions. From the docs for declare():
"This is the most flexible way to declare versions. Consider using it to
normalize version strings." With that in mind, the input has to allow
"not normal" version strings.

This patch restores the old behaviour, fixing usage of declare() and
parse(). I'm not super comfortable with how parse() is supposed to work,
so I didn't add any tests for it. But I did add tests for declare().
@theory
Copy link
Owner

theory commented Aug 21, 2018

I love that you've added tests and didn't need to delete any. What do you think, @hoppfrosch?

@hoppfrosch
Copy link
Collaborator

Looks fine as far as I can oversee aTM - I'll pull the request, as soon as I've a little spare time :-)

@theory
Copy link
Owner

theory commented Aug 6, 2019

This issue broke PGXN today. Would love to see it resolved and released.

@theory theory closed this in 28d4413 May 9, 2020
@theory theory closed this in #12 May 9, 2020
theory added a commit that referenced this pull request May 9, 2020
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 this pull request may close these issues.

None yet

3 participants