cvs: php-src /pear/PEAR Common.php Installer.php

From: Date: Mon, 06 Oct 2003 15:15:56 +0000
Subject: cvs: php-src /pear/PEAR Common.php Installer.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-13428@lists.php.net to get a copy of this message
cox Mon Oct 6 11:15:56 2003 EDT Modified files: /php-src/pear/PEAR Common.php Installer.php Log: better version checks (contributed by Roman) Index: php-src/pear/PEAR/Common.php diff -u php-src/pear/PEAR/Common.php:1.109 php-src/pear/PEAR/Common.php:1.110 --- php-src/pear/PEAR/Common.php:1.109 Mon Sep 15 23:26:05 2003 +++ php-src/pear/PEAR/Common.php Mon Oct 6 11:15:56 2003 @@ -17,7 +17,7 @@ // | Tomas V.V.Cox <cox@idecnet.com> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.109 2003/09/16 03:26:05 cellog Exp $ +// $Id: Common.php,v 1.110 2003/10/06 15:15:56 cox Exp $ require_once 'PEAR.php'; require_once 'Archive/Tar.php'; @@ -26,10 +26,15 @@ // {{{ 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 @@ } $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 @@ 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'; @@ -1552,6 +1561,24 @@ function validPackageName($name) { return (bool)preg_match(PEAR_COMMON_PACKAGE_NAME_PREG, $name); + } + + + // }}} + // {{{ 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); } Index: php-src/pear/PEAR/Installer.php diff -u php-src/pear/PEAR/Installer.php:1.135 php-src/pear/PEAR/Installer.php:1.136 --- php-src/pear/PEAR/Installer.php:1.135 Sun Oct 5 15:10:56 2003 +++ php-src/pear/PEAR/Installer.php Mon Oct 6 11:15:56 2003 @@ -18,7 +18,7 @@ // | Martin Jansen <mj@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Installer.php,v 1.135 2003/10/05 19:10:56 cox Exp $ +// $Id: Installer.php,v 1.136 2003/10/06 15:15:56 cox Exp $ require_once 'PEAR/Common.php'; require_once 'PEAR/Registry.php'; @@ -1062,10 +1062,6 @@ 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 @@ 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

« previous php.pear.cvs (#13428) next »