diff options
| author | Damien Regad <dregad@mantisbt.org> | 2015-12-03 17:18:32 +0000 |
|---|---|---|
| committer | Damien Regad <dregad@mantisbt.org> | 2015-12-03 17:18:32 +0000 |
| commit | 08292da59bf038999afb550be3bbda19aedd4181 (patch) | |
| tree | c59cd496f6966279b865509afe0c1dde9d85b6d4 | |
| parent | 453f080abb35e2ba5722217f1b53f605738322df (diff) | |
| download | adodb-08292da59bf038999afb550be3bbda19aedd4181.tar.gz adodb-08292da59bf038999afb550be3bbda19aedd4181.tar.bz2 adodb-08292da59bf038999afb550be3bbda19aedd4181.zip | |
ADOConnection::Version() now handles SemVer
In the past, ADOdb versions were numbered X.YY, and hot fixes were
identified by an optional letter suffix, e.g. 5.17, 5.18a. Starting with
5.20, we switched to Semantic Versioning.
The regex in ADOConnection::Version() was not adjusted to reflect this,
and the function incorrectly returns '5.20' instead of '5.20.0'.
The code now correctly handles SemVer version numbers, and also allows
the following pre-production suffixes: dev, alpha, beta, rc; the last 3
must be followed by an additional version number (e.g. 5.21.0-beta.1).
In case the ADOdb version string (defined in $ADODB_vers global) does
not match the regex, the function outputs a warning and falls back to
returning a substring starting with 1st character (excluding leading 'v'
if present), until the first whitespace or the end of the string).
Fixes #164
| -rw-r--r-- | adodb.inc.php | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/adodb.inc.php b/adodb.inc.php index 8fbd5f04..dc6f4ca1 100644 --- a/adodb.inc.php +++ b/adodb.inc.php @@ -535,12 +535,21 @@ if (!defined('_ADODB_LAYER')) { static function Version() { global $ADODB_vers; - $ok = preg_match( '/^[Vv]?([0-9]\.[0-9]+(dev|[a-z])?)/', $ADODB_vers, $matches ); - if (!$ok) { - return (float) substr($ADODB_vers,1); - } else { - return $matches[1]; + // Semantic Version number matching regex + $regex = '^[vV]?(\d+\.\d+\.\d+' // Version number (X.Y.Z) with optional 'V' + . '(?:-(?:' // Optional preprod version: a '-' + . 'dev|' // followed by 'dev' + . '(?:(?:alpha|beta|rc)(?:\.\d+))' // or a preprod suffix and version number + . '))?)(?:\s|$)'; // Whitespace or end of string + + if (!preg_match("/$regex/", $ADODB_vers, $matches)) { + // This should normally not happen... Return whatever is between the start + // of the string and the first whitespace (or the end of the string). + self::outp("Invalid version number: '$ADODB_vers'", 'Version'); + $regex = '^[vV]?(.*?)(?:\s|$)'; + preg_match("/$regex/", $ADODB_vers, $matches); } + return $matches[1]; } /** |
