Skip to content

Commit

Permalink
Allow 2 digits in the patch part of the version
Browse files Browse the repository at this point in the history
Version 5.3.10 contains two digits in the patch part of the exact
version and could not be installed due to an UnexpectedValueException
because the version regex only allowed single digits.

I decided to only extend the patch part of the version regex to allow 2
digits because the benefits of catching mistyped version numbers that do
not exist (5.3.10 is the first version with a multiple digit number)
outweights the flexibility of allowing 2 digits in the major and minor
parts as well. This might have to change if 5.10.*.* or 10.*.*.*
approaches.

Fixes #4
  • Loading branch information
PhilippBaschke committed Jul 20, 2016
1 parent 045980f commit f18e537
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ACFProInstaller/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected function validateVersion($version)
{
// \A = start of string, \Z = end of string
// See: http://stackoverflow.com/a/34994075
$major_minor_patch_optional = '/\A\d\.\d\.\d(?:\.\d)?\Z/';
$major_minor_patch_optional = '/\A\d\.\d\.\d{1,2}(?:\.\d)?\Z/';

if (!preg_match($major_minor_patch_optional, $version)) {
throw new \UnexpectedValueException(
Expand Down
5 changes: 5 additions & 0 deletions tests/ACFProInstaller/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ public function testExactVersionWith4DigitsPassesValidation()
$this->versionPassesValidationHelper('1.2.3.4');
}

public function testExactVersionWithPatchDoubleDigitsPassesValidation()
{
$this->versionPassesValidationHelper('1.2.30');
}

protected function versionFailsValidationHelper($version)
{
// Expect an Exception
Expand Down

1 comment on commit f18e537

@srsimonson
Copy link

Choose a reason for hiding this comment

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

5.10.* has arrived. Trying to update any versions 5.10.* throws the "UnexpectedValueException" error saying "Invalid version string '5.10.2' "

Please sign in to comment.