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

Issue/91. Handle patch correctly. #98

Merged
merged 11 commits into from
Dec 17, 2019
Merged

Issue/91. Handle patch correctly. #98

merged 11 commits into from
Dec 17, 2019

Conversation

slash3b
Copy link
Contributor

@slash3b slash3b commented Dec 13, 2019

TLDR: priority fix and added some more tests

Fixed major flaw — turned out within extent of same version patch flag is of the highest priority.
Priority sequence should be the following:

1.1-alpha < 1.1-beta < 1.1-rc < 1.1-stable < 1.1 < 1.1-p

diff between old version and fixed one:

slash3b@Nostromo ~/P/SecurityAdvisoriesBuilder (issue/91)> diff -u old_composer.json build/composer.json
--- old_composer.json   2019-12-13 18:25:18.956262258 +0200
+++ build/composer.json 2019-12-13 18:27:19.958957880 +0200
@@ -75,7 +75,7 @@
         "league/commonmark": "<0.18.3",
         "magento/magento1ce": "<1.9.4.3",
         "magento/magento1ee": ">=1,<1.14.4.3",
-        "magento/product-community-edition": ">=2,<2.2.10|>=2.3,<2.3.2",
+        "magento/product-community-edition": ">=2,<2.2.10|>=2.3,<2.3.2-p.2",
         "monolog/monolog": ">=1.8,<1.12",
         "namshi/jose": "<2.2",
         "onelogin/php-saml": "<2.10.4",

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looking good, but we need checks among -p1, -p2 and -p3 .

@nikolaposa you might be interested in this sort of patch too 👍

}

/**
* @return mixed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This js an array<string, array<int, string|array<string, array<string, array<string>>>> or such 😵😵😵

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know how to correct this 😓
Is @return mixed okay ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a test data provider: we're good for now 👍

test/RoaveTest/SecurityAdvisories/VersionTest.php Outdated Show resolved Hide resolved
src/Roave/SecurityAdvisories/Version.php Outdated Show resolved Hide resolved
complex than I expected.

Apart from designating Flag class for all the logic, spaceship operator
logic was ditched — it became too complex so insted we just use boolean.

PRIORITY map in Flag class contains null, looks ugly, but allowed to
throw away lots of checks and makes flag comparison more obvious and
"natural" I would say.
@nikolaposa
Copy link

Thanks for the ping @Ocramius. 👍

On a different note, these days I'm working on Version 4.0.0, lots of backward-incompatible improvements in it (https://github.com/nikolaposa/version/blob/master/CHANGELOG.md#unreleased). 😒 BackwardCompatibilityCheck library is by far the biggest dependent so I'll help you with migrating, expect a PR soon!

private const PRIORITY = [
'patch' => 5,
'p' => 5,
null => 4, // special case of clean version, e.g. 1.2.3
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it looks a bit ugly, but when I added this null in the map, it helped to ditch so many useless checks.
So I think it is ugly and... elegant at the same time 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null is not a valid array key. This is probably adding the empty string instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I'd say it actually is a valid key, at least I'm being able to get value from array by null

But you got me thinking, and yes null is not very good key. I'm going to change it to string value with some meaning attached.

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end empty string was the best variant. I did push update.

{
$this->versionNumbers = self::removeTrailingZeroes(...array_map('intval', explode('.', $matches['version'])));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just moved this logic from fromString static method to unload it a little bit

}

public function equalTo(self $other) : bool
{
return $other->versionNumbers === $this->versionNumbers &&
$this->stabilityEqualTo($other);
return $other->versionNumbers === $this->versionNumbers
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplified logic, no need for stabilityEqualTo

// compare with version lower
['2.3.2-p2', '2.3.1', true, false],
// compare two patches but with additional stability versions like 1-p1 and 1-p2 so the p2 will be greater
['2.3.2-p1', '2.3.2-p2', false, true],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius I do this p1 vs p2 comparison here.
Also I have to admit it starts to get out of hand, data providers grow and it is a bit hard to navigate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but that's combinatory logic with edge cases 🤷‍♀️

The good thing is that I'm not (currently) aware of further edge cases

@slash3b slash3b marked this pull request as ready for review December 14, 2019 17:31
@slash3b
Copy link
Contributor Author

slash3b commented Dec 14, 2019

It is ready for review 🤞

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, excellent work @slash3b!

@Ocramius Ocramius merged commit 1d40c01 into Roave:master Dec 17, 2019
@Ocramius Ocramius self-assigned this Dec 17, 2019
@slash3b
Copy link
Contributor Author

slash3b commented Dec 17, 2019

@Ocramius thank you!
I'm so glad I could help ^^

@Ocramius
Copy link
Member

@nikolaposa
Copy link

nikolaposa commented Dec 22, 2019

@slash3b What does -p actually denote? Is that some custom pre-release identifier? It definitely isn't Semver-compliant because the correct order should be:

1.1-alpha < 1.1-beta < 1.1-p < 1.1-rc < 1.1-stable < 1.1

Precedence for two pre-release versions with the same major, minor, and patch version MUST be determined by comparing each dot separated identifier from left to right until a difference is found as follows: identifiers consisting of only digits are compared numerically and identifiers with letters or hyphens are compared lexically in ASCII sort order.

@Ocramius
Copy link
Member

-p is for -patch, so 1.2.0-p1 is a bit higher than 1.2.0. I was as confused as you when Magento decided to release with this modifier 🤷‍♀️

@nikolaposa
Copy link

Oh no.

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

Successfully merging this pull request may close these issues.

None yet

4 participants