summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas V.V.Cox <cox@php.net>2003-10-06 15:15:56 +0000
committerTomas V.V.Cox <cox@php.net>2003-10-06 15:15:56 +0000
commit164b593d236c27bb22226508602b27f14961f302 (patch)
tree58a17d8a6576a7b19d30b148a22daaa76640c8f5
parenta1b5c341a21ede2751521765f1e52587212a8b47 (diff)
downloadphp-git-164b593d236c27bb22226508602b27f14961f302.tar.gz
better version checks (contributed by Roman)
-rw-r--r--pear/PEAR/Common.php35
-rw-r--r--pear/PEAR/Installer.php9
2 files changed, 32 insertions, 12 deletions
diff --git a/pear/PEAR/Common.php b/pear/PEAR/Common.php
index e4cfa7515f..478ca11c16 100644
--- a/pear/PEAR/Common.php
+++ b/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';
@@ -1556,6 +1565,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()
diff --git a/pear/PEAR/Installer.php b/pear/PEAR/Installer.php
index 19c8b67a32..556368ec9a 100644
--- a/pear/PEAR/Installer.php
+++ b/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