improves regexes parsing plugins metadata

git-svn-id: http://piwigo.org/svn/trunk@28969 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
mistic100
2014-07-06 14:05:05 +00:00
parent dbedfd173f
commit 1633d8ffaa
4 changed files with 21 additions and 19 deletions
+6 -5
View File
@@ -158,24 +158,24 @@ UPDATE '.USER_INFOS_TABLE.'
); );
$plg_data = implode( '', file($path.'/common.lang.php') ); $plg_data = implode( '', file($path.'/common.lang.php') );
if ( preg_match("|Language Name: (.*)|", $plg_data, $val) ) if (preg_match("|Language Name:\\s*(.+)|", $plg_data, $val))
{ {
$language['name'] = trim( $val[1] ); $language['name'] = trim( $val[1] );
$language['name'] = convert_charset($language['name'], 'utf-8', $target_charset); $language['name'] = convert_charset($language['name'], 'utf-8', $target_charset);
} }
if (preg_match("|Version: (.*)|", $plg_data, $val)) if (preg_match("|Version:\\s*([\\w.-]+)|", $plg_data, $val))
{ {
$language['version'] = trim($val[1]); $language['version'] = trim($val[1]);
} }
if ( preg_match("|Language URI: (.*)|", $plg_data, $val) ) if (preg_match("|Language URI:\\s*(https?:\\/\\/.+)|", $plg_data, $val))
{ {
$language['uri'] = trim($val[1]); $language['uri'] = trim($val[1]);
} }
if ( preg_match("|Author: (.*)|", $plg_data, $val) ) if (preg_match("|Author:\\s*(.+)|", $plg_data, $val))
{ {
$language['author'] = trim($val[1]); $language['author'] = trim($val[1]);
} }
if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) if (preg_match("|Author URI:\\s*(https?:\\/\\/.+)|", $plg_data, $val))
{ {
$language['author uri'] = trim($val[1]); $language['author uri'] = trim($val[1]);
} }
@@ -184,6 +184,7 @@ UPDATE '.USER_INFOS_TABLE.'
list( , $extension) = explode('extension_view.php?eid=', $language['uri']); list( , $extension) = explode('extension_view.php?eid=', $language['uri']);
if (is_numeric($extension)) $language['extension'] = $extension; if (is_numeric($extension)) $language['extension'] = $extension;
} }
// IMPORTANT SECURITY ! // IMPORTANT SECURITY !
$language = array_map('htmlspecialchars', $language); $language = array_map('htmlspecialchars', $language);
$this->fs_languages[$file] = $language; $this->fs_languages[$file] = $language;
+7 -6
View File
@@ -257,15 +257,15 @@ DELETE FROM '. PLUGINS_TABLE .'
); );
$plg_data = file_get_contents($path.'/main.inc.php', null, null, 0, 2048); $plg_data = file_get_contents($path.'/main.inc.php', null, null, 0, 2048);
if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) if (preg_match("|Plugin Name:\\s*(.+)|", $plg_data, $val))
{ {
$plugin['name'] = trim( $val[1] ); $plugin['name'] = trim( $val[1] );
} }
if (preg_match("|Version: (.*)|", $plg_data, $val)) if (preg_match("|Version:\\s*([\\w.-]+)|", $plg_data, $val))
{ {
$plugin['version'] = trim($val[1]); $plugin['version'] = trim($val[1]);
} }
if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) ) if (preg_match("|Plugin URI:\\s*(https?:\\/\\/.+)|", $plg_data, $val))
{ {
$plugin['uri'] = trim($val[1]); $plugin['uri'] = trim($val[1]);
} }
@@ -273,15 +273,15 @@ DELETE FROM '. PLUGINS_TABLE .'
{ {
$plugin['description'] = trim($desc); $plugin['description'] = trim($desc);
} }
elseif ( preg_match("|Description: (.*)|", $plg_data, $val) ) elseif (preg_match("|Description:\\s*(.+)|", $plg_data, $val))
{ {
$plugin['description'] = trim($val[1]); $plugin['description'] = trim($val[1]);
} }
if ( preg_match("|Author: (.*)|", $plg_data, $val) ) if (preg_match("|Author:\\s*(.+)|", $plg_data, $val))
{ {
$plugin['author'] = trim($val[1]); $plugin['author'] = trim($val[1]);
} }
if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) if (preg_match("|Author URI:\\s*(https?:\\/\\/.+)|", $plg_data, $val))
{ {
$plugin['author uri'] = trim($val[1]); $plugin['author uri'] = trim($val[1]);
} }
@@ -290,6 +290,7 @@ DELETE FROM '. PLUGINS_TABLE .'
list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']);
if (is_numeric($extension)) $plugin['extension'] = $extension; if (is_numeric($extension)) $plugin['extension'] = $extension;
} }
// IMPORTANT SECURITY ! // IMPORTANT SECURITY !
$plugin = array_map('htmlspecialchars', $plugin); $plugin = array_map('htmlspecialchars', $plugin);
$this->fs_plugins[$file] = $plugin; $this->fs_plugins[$file] = $plugin;
+7 -7
View File
@@ -375,17 +375,17 @@ SELECT
'author' => '', 'author' => '',
'mobile' => false, 'mobile' => false,
); );
$theme_data = implode( '', file($path.'/themeconf.inc.php') ); $theme_data = implode('', file($path.'/themeconf.inc.php'));
if ( preg_match("|Theme Name: (.*)|", $theme_data, $val) ) if (preg_match("|Theme Name:\\s*(.+)|", $theme_data, $val))
{ {
$theme['name'] = trim( $val[1] ); $theme['name'] = trim( $val[1] );
} }
if (preg_match("|Version: (.*)|", $theme_data, $val)) if (preg_match("|Version:\\s*([\\w.-]+)|", $theme_data, $val))
{ {
$theme['version'] = trim($val[1]); $theme['version'] = trim($val[1]);
} }
if ( preg_match("|Theme URI: (.*)|", $theme_data, $val) ) if (preg_match("|Theme URI:\\s*(https?:\\/\\/.+)|", $theme_data, $val))
{ {
$theme['uri'] = trim($val[1]); $theme['uri'] = trim($val[1]);
} }
@@ -393,15 +393,15 @@ SELECT
{ {
$theme['description'] = trim($desc); $theme['description'] = trim($desc);
} }
elseif ( preg_match("|Description: (.*)|", $theme_data, $val) ) elseif (preg_match("|Description:\\s*(.+)|", $theme_data, $val))
{ {
$theme['description'] = trim($val[1]); $theme['description'] = trim($val[1]);
} }
if ( preg_match("|Author: (.*)|", $theme_data, $val) ) if (preg_match("|Author:\\s*(.+)|", $theme_data, $val))
{ {
$theme['author'] = trim($val[1]); $theme['author'] = trim($val[1]);
} }
if ( preg_match("|Author URI: (.*)|", $theme_data, $val) ) if (preg_match("|Author URI:\\s*(https?:\\/\\/.+)|", $theme_data, $val))
{ {
$theme['author uri'] = trim($val[1]); $theme['author uri'] = trim($val[1]);
} }
+1 -1
View File
@@ -380,7 +380,7 @@ function autoupdate_plugin(&$plugin)
$i++; $i++;
if ($i < 2) continue; // first lines are typically "<?php" and "/*" if ($i < 2) continue; // first lines are typically "<?php" and "/*"
if (preg_match('#Version: ([\\w.-]+)#', $line, $matches)) if (preg_match('/Version:\\s*([\\w.-]+)/', $line, $matches))
{ {
$fs_version = $matches[1]; $fs_version = $matches[1];
} }