-
Notifications
You must be signed in to change notification settings - Fork 10
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
a bit of a clean up for regexes #146
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,44 +20,25 @@ | |
|
||
namespace Roave\SecurityAdvisories; | ||
|
||
/** | ||
* @see https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string | ||
* | ||
* @fixme: throw this garbage away and use existing regexp from semver.org | ||
*/ | ||
final class Matchers | ||
{ | ||
// pattern that matches full version only, without boundary sign | ||
public const TAGGED_VERSION_MATCHER = '\s*(?<version>(?:\d+\.)*\d+)' . | ||
'(?:-' . // dash is required for correct version | ||
'(?<flag>stable|beta|b|rc|alpha|a|patch|p)' . | ||
'[._-]?' . | ||
'(?<stability_numbers>(?:\d+\.)*\d+)?' . | ||
')?\s*'; | ||
|
||
private const UNTAGGED_VERSION_MATCHER = '((?:\d+\.)*\d+)' . | ||
'(?:-' . | ||
'(stable|beta|b|rc|alpha|a|patch|p)' . | ||
'[._-]?' . | ||
'((?:\d+\.)*\d+)?' . | ||
')?'; | ||
|
||
// pattern that ensures we have a correct boundary in the right place | ||
public const BOUNDARY_MATCHER = '/^\s*(?<boundary><|<=|=|>=|>)\s*' . | ||
self::TAGGED_VERSION_MATCHER . | ||
'\s*$/'; | ||
|
||
public const CLOSED_RANGE_MATCHER = '/^>(=?)\s*' . | ||
self::UNTAGGED_VERSION_MATCHER . | ||
'\s*,\s*<(=?)\s*' . | ||
self::UNTAGGED_VERSION_MATCHER . | ||
'$/'; | ||
|
||
public const LEFT_OPEN_RANGE_MATCHER = '/^<(=?)\s*' . | ||
self::UNTAGGED_VERSION_MATCHER . | ||
'$/'; | ||
|
||
public const RIGHT_OPEN_RANGE_MATCHER = '/^>(=?)\s*' . | ||
self::UNTAGGED_VERSION_MATCHER . | ||
'$/'; | ||
/* | ||
* Pattern that matches full version only, without boundary sign. | ||
* Was "inspired" by semver regexp -- https://github.com/composer/semver/blob/master/src/VersionParser.php | ||
* Regular expression was tailored to the needs of the package and catches: | ||
* - main version, e.g. 2.1.0 | ||
* - stability flag, e.g. alpha, beta and etc. | ||
* - stability numbers | ||
*/ | ||
public const TAGGED_VERSION_MATCHER = '\s*(?<version>(?:\d+\.)*\d+)(?:-(?<flag>stable|beta|b|rc|alpha|a|patch|p)[._-]?(?<stability_numbers>(?:\d+\.)*\d+)?)?\s*'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any functional change in this patch? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no functional change in this patch, just wanted it to be a bit more clean. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I must say that I find the previous version cleaner/easier to follow :| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, then lets close it. No worries. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, thanks for the effort anyway! |
||
|
||
private const UNTAGGED_VERSION_MATCHER = '((?:\d+\.)*\d+)(?:-(stable|beta|b|rc|alpha|a|patch|p)[._-]?((?:\d+\.)*\d+)?)?'; | ||
|
||
public const BOUNDARY_MATCHER = '/^\s*(?<boundary><|<=|=|>=|>)\s*' . self::TAGGED_VERSION_MATCHER . '\s*$/'; | ||
|
||
public const CLOSED_RANGE_MATCHER = '/^>(=?)\s*' . self::UNTAGGED_VERSION_MATCHER . '\s*,\s*<(=?)\s*' . self::UNTAGGED_VERSION_MATCHER . '$/'; | ||
|
||
public const LEFT_OPEN_RANGE_MATCHER = '/^<(=?)\s*' . self::UNTAGGED_VERSION_MATCHER . '$/'; | ||
|
||
public const RIGHT_OPEN_RANGE_MATCHER = '/^>(=?)\s*' . self::UNTAGGED_VERSION_MATCHER . '$/'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reads very clunky 😬