Browse Source

better version checks (contributed by Roman)

PEAR_1_4DEV
Tomas V.V.Cox 23 years ago
parent
commit
164b593d23
  1. 35
      pear/PEAR/Common.php
  2. 9
      pear/PEAR/Installer.php

35
pear/PEAR/Common.php

@ -26,10 +26,15 @@ require_once 'PEAR/Config.php';
// {{{ constants and globals
define('PEAR_COMMON_PACKAGE_NAME_PREG', '/^[A-Za-z][a-zA-Z0-9_]+$/');
define('_PEAR_COMMON_PACKAGE_NAME_PREG', '[A-Za-z][a-zA-Z0-9_]+');
define('PEAR_COMMON_PACKAGE_NAME_PREG', '/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '$/');
// this should allow: 1, 1.0, 1.0RC1, 1.0dev, 1.0dev123234234234, 1.0a1, 1.0b1, 1.0pl1
define('_PEAR_COMMON_PACKAGE_VERSION_PREG', '\d+(?:\.\d+)*(?:[a-z]+\d*)?');
define('PEAR_COMMON_PACKAGE_VERSION_PREG', '/^' . _PEAR_COMMON_PACKAGE_VERSION_PREG . '$/i');
// XXX far from perfect :-)
define('PEAR_COMMON_PACKAGE_DOWNLOAD_PREG', '/^([A-Za-z][a-zA-Z0-9_]+)(-([.0-9a-zA-Z]+))?$/');
define('PEAR_COMMON_PACKAGE_DOWNLOAD_PREG', '/^(' . _PEAR_COMMON_PACKAGE_NAME_PREG . ')(-([.0-9a-zA-Z]+))?$/');
/**
* List of temporary files and directories registered by
@ -1036,8 +1041,10 @@ class PEAR_Common extends PEAR
}
$errors = array();
$warnings = array();
if (empty($info['package'])) {
if (!isset($info['package'])) {
$errors[] = 'missing package name';
} elseif (!$this->validPackageName($info['package'])) {
$errors[] = 'invalid package name';
}
if (empty($info['summary'])) {
$errors[] = 'missing summary';
@ -1050,8 +1057,10 @@ class PEAR_Common extends PEAR
if (empty($info['release_license'])) {
$errors[] = 'missing license';
}
if (empty($info['version'])) {
if (!isset($info['version'])) {
$errors[] = 'missing version';
} elseif (!$this->validPackageVersion($info['version'])) {
$errors[] = 'invalid package version';
}
if (empty($info['release_state'])) {
$errors[] = 'missing release state';
@ -1555,6 +1564,24 @@ class PEAR_Common extends PEAR
}
// }}}
// {{{ validPackageVersion()
/**
* Test whether a string contains a valid package version.
*
* @param string $ver the package version to test
*
* @return bool
*
* @access public
*/
function validPackageVersion($ver)
{
return (bool)preg_match(PEAR_COMMON_PACKAGE_VERSION_PREG, $ver);
}
// }}}
// {{{ downloadHttp()

9
pear/PEAR/Installer.php

@ -1062,10 +1062,6 @@ class PEAR_Installer extends PEAR_Common
return $this->raiseError("$pkgname already installed");
}
} else {
// checks to do only when upgrading packages
/* if (!$this->registry->packageExists($pkgname)) {
return $this->raiseError("$pkgname not installed");
}*/
if ($this->registry->packageExists($pkgname)) {
$v1 = $this->registry->packageInfo($pkgname, 'version');
$v2 = $pkginfo['version'];
@ -1095,12 +1091,9 @@ class PEAR_Installer extends PEAR_Common
null, PEAR_ERROR_DIE);
}
// don't want strange characters
$pkgname = ereg_replace ('[^a-zA-Z0-9._]', '_', $pkginfo['package']);
$pkgversion = ereg_replace ('[^a-zA-Z0-9._\-]', '_', $pkginfo['version']);
$tmp_path = dirname($descfile);
if (substr($pkgfile, -4) != '.xml') {
$tmp_path .= DIRECTORY_SEPARATOR . $pkgname . '-' . $pkgversion;
$tmp_path .= DIRECTORY_SEPARATOR . $pkgname . '-' . $pkginfo['version'];
}
// ==> XXX This part should be removed later on

Loading…
Cancel
Save