Commit fa4a0fe5 authored by Cédric Anne's avatar Cédric Anne
Browse files

Remove useless polyfills; add PHP 8.0 functions polyfill

parent 72f4ea44
......@@ -60,8 +60,10 @@ The present file will list all changes made to the project; according to the
- `RuleImportComputer` class
- `RuleImportComputerCollection` class
- `Toolbox::clean_cross_side_scripting_deep()`
- `Toolbox::endsWith()`
- `Toolbox::getHtmlToDisplay()`
- `Toolbox::unclean_cross_side_scripting_deep()`
- `Toolbox::startsWith()`
#### Removed
- jQueryUI has been partially removed and remaining widgets will be removed in a near future.
......
......@@ -57,6 +57,7 @@
"symfony/cache": "^5.2",
"symfony/console": "^5.0",
"symfony/dom-crawler": "^5.3",
"symfony/polyfill-php80": "^1.23",
"true/punycode": "^2.1",
"twig/string-extra": "^3.3",
"twig/twig": "^3.3",
......@@ -76,8 +77,12 @@
"replace": {
"paragonie/random_compat": "*",
"symfony/polyfill-ctype": "*",
"symfony/polyfill-intl-grapheme": "*",
"symfony/polyfill-intl-idn": "*",
"symfony/polyfill-php72": "*"
"symfony/polyfill-intl-normalizer": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php73": "*",
"symfony/polyfill-php74": "*"
},
"suggest": {
"ext-ldap": "Used to provide LDAP authentication and synchronization",
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "80ea90312607e10a50eda8286f18d8f8",
"content-hash": "bb6fcc6d5bc102b016684269a454acec",
"packages": [
{
"name": "blueimp/jquery-file-upload",
......@@ -3754,171 +3754,6 @@
],
"time": "2021-08-29T19:32:13+00:00"
},
{
"name": "symfony/polyfill-intl-grapheme",
"version": "v1.23.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-grapheme.git",
"reference": "16880ba9c5ebe3642d1995ab866db29270b36535"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/16880ba9c5ebe3642d1995ab866db29270b36535",
"reference": "16880ba9c5ebe3642d1995ab866db29270b36535",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"suggest": {
"ext-intl": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.23-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Intl\\Grapheme\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for intl's grapheme_* functions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"grapheme",
"intl",
"polyfill",
"portable",
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.23.1"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-05-27T12:26:48+00:00"
},
{
"name": "symfony/polyfill-intl-normalizer",
"version": "v1.23.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-normalizer.git",
"reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8590a5f561694770bdcd3f9b5c69dde6945028e8",
"reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"suggest": {
"ext-intl": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.23-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Intl\\Normalizer\\": ""
},
"files": [
"bootstrap.php"
],
"classmap": [
"Resources/stubs"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for intl's Normalizer class and related functions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"intl",
"normalizer",
"polyfill",
"portable",
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.23.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-02-19T12:13:01+00:00"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.23.1",
......@@ -3999,85 +3834,6 @@
],
"time": "2021-05-27T12:26:48+00:00"
},
{
"name": "symfony/polyfill-php73",
"version": "v1.23.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php73.git",
"reference": "fba8933c384d6476ab14fb7b8526e5287ca7e010"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/fba8933c384d6476ab14fb7b8526e5287ca7e010",
"reference": "fba8933c384d6476ab14fb7b8526e5287ca7e010",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.23-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Php73\\": ""
},
"files": [
"bootstrap.php"
],
"classmap": [
"Resources/stubs"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"polyfill",
"portable",
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php73/tree/v1.23.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-02-19T12:13:01+00:00"
},
{
"name": "symfony/polyfill-php80",
"version": "v1.23.1",
......
......@@ -55,7 +55,7 @@ $filepath = $dir.$_GET["name"];
if ((basename($_GET["name"]) != $_GET["name"])
|| (basename($_GET["plugin"]) != $_GET["plugin"])
|| !Toolbox::startsWith(realpath($filepath), realpath(GLPI_PLUGIN_DOC_DIR))
|| !str_starts_with(realpath($filepath), realpath(GLPI_PLUGIN_DOC_DIR))
|| !Document::isImage($filepath)) {
Event::log("-1", "system", 1, "security",
......
......@@ -3037,7 +3037,7 @@ abstract class API {
});
$crawler->filterXPath('//select')->each(function (Crawler $node, $i) use (&$inputs) {
$type = 'select';
if (Toolbox::startsWith($node->attr('id'), 'dropdown_')) {
if (str_starts_with($node->attr('id'), 'dropdown_')) {
$type = 'dropdown';
}
$inputs[] = [
......
......@@ -2135,6 +2135,8 @@ class Config extends CommonDBTM {
'check' => 'Twig\\Environment' ],
[ 'name' => 'twig/string-extra',
'check' => 'Twig\\Extra\\String\\StringExtension' ],
[ 'name' => 'symfony/polyfill-php80',
'check' => 'str_contains' ],
];
if (Toolbox::canUseCAS()) {
$deps[] = [
......
......@@ -198,7 +198,7 @@ if (!isset($skip_db_check) && !file_exists(GLPI_CONFIG_DIR . "/config_db.php"))
}
} else if (isset($CFG_GLPI['dbversion']) && strlen($CFG_GLPI['dbversion']) > 40) {
//got a dev version in database, but current stable
if (Toolbox::startsWith($CFG_GLPI['dbversion'], GLPI_SCHEMA_VERSION)) {
if (str_starts_with($CFG_GLPI['dbversion'], GLPI_SCHEMA_VERSION)) {
$older = true;
} else {
$newer = true;
......
......@@ -53,7 +53,7 @@ final class DbUtils {
* @return string field name used for a foreign key to the parameter table
*/
public function getForeignKeyFieldForTable($table) {
if (!Toolbox::startsWith($table, 'glpi_')) {
if (!str_starts_with($table, 'glpi_')) {
return "";
}
return substr($table, 5)."_id";
......@@ -86,7 +86,7 @@ final class DbUtils {
}
// If $fkname begin with _ strip it
if (Toolbox::startsWith($fkname, '_')) {
if (str_starts_with($fkname, '_')) {
$fkname = substr($fkname, 1);
}
......
......@@ -100,7 +100,7 @@ class GLPIMailer extends PHPMailer {
public static function validateAddress($address, $patternselect = "pcre8") {
$isValid = parent::validateAddress($address, $patternselect);
if (!$isValid && Toolbox::endsWith($address, '@localhost')) {
if (!$isValid && str_ends_with($address, '@localhost')) {
//since phpmailer6, @localhost address are no longer valid...
$isValid = parent::ValidateAddress($address . '.me');
}
......
......@@ -6467,7 +6467,7 @@ HTML;
$ckey .= '_' . $file;
if (!Toolbox::endsWith($file, '.scss')) {
if (!str_ends_with($file, '.scss')) {
// Prevent include of file if ext is not .scss
$file .= '.scss';
}
......@@ -6490,7 +6490,7 @@ HTML;
// Prevent import of a file from ouside GLPI dir
$path = realpath($path);
if (!Toolbox::startsWith($path, realpath(GLPI_ROOT))) {
if (!str_starts_with($path, realpath(GLPI_ROOT))) {
Toolbox::logWarning('Requested file ' . $path . ' is outside GLPI file tree.');
return '';
}
......
......@@ -108,7 +108,7 @@ class Software extends InventoryAsset
if (!property_exists($val, 'name')
|| ($val->name == ''
|| Toolbox::startsWith(Toolbox::slugify($val->name), 'nok_')
|| str_starts_with(Toolbox::slugify($val->name), 'nok_')
)
) {
if (property_exists($val, 'guid') && $val->guid != '') {
......
......@@ -693,7 +693,7 @@ HTML;
// Use "marketplace.download.php" proxy if archive is downloadable from GLPI marketplace plugins API
// as this API will refuse to serve the archive if registration key is not set in headers.
$download_url = Toolbox::startsWith($plugin_data['installation_url'], GLPI_MARKETPLACE_PLUGINS_API_URI)
$download_url = str_starts_with($plugin_data['installation_url'], GLPI_MARKETPLACE_PLUGINS_API_URI)
? $CFG_GLPI['root_doc'] . '/front/marketplace.download.php?key=' . $plugin_key
: $plugin_data['installation_url'];
......
......@@ -622,7 +622,7 @@ class MassiveAction {
if (isset($actions[$actiontodel])) {
unset($actions[$actiontodel]);
} else {
if (Toolbox::startsWith($actiontodel, '*:')) {
if (str_starts_with($actiontodel, '*:')) {
foreach (array_keys($actions) as $action) {
if (preg_match('/[^:]+:' . str_replace('*:', '', $actiontodel . '/'), $action)
&& !in_array($action, $whitedlisted_actions)
......@@ -631,7 +631,7 @@ class MassiveAction {
}
}
}
if (Toolbox::endsWith($actiontodel, ':*')) {
if (str_ends_with($actiontodel, ':*')) {
foreach (array_keys($actions) as $action) {
if (preg_match('/' . str_replace(':*', '', $actiontodel . ':.+/'), $action)
&& !in_array($action, $whitedlisted_actions)
......
......@@ -626,8 +626,8 @@ class Migration {
unset($this->uniques[$oldtable]);
}
} else {
if (Toolbox::startsWith($oldtable, 'glpi_plugin_')
|| Toolbox::startsWith($newtable, 'glpi_plugin_')
if (str_starts_with($oldtable, 'glpi_plugin_')
|| str_starts_with($newtable, 'glpi_plugin_')
) {
return;
}
......
......@@ -362,7 +362,7 @@ class Plugin extends CommonDBTM {
return true;
}
return Toolbox::startsWith($dir, $plugin_key . '_');
return str_starts_with($dir, $plugin_key . '_');
});
foreach ($plugin_folders as $plugin_folder) {
......
......@@ -49,7 +49,7 @@ class QueryParam {
if ($value == null || trim($value) == '') {
$value = '?';
}
if ($value != '?' && !Toolbox::startsWith($value, ':')) {
if ($value != '?' && !str_starts_with($value, ':')) {
$value = ':' . $value;
}
$this->value = $value;
......
......@@ -226,7 +226,7 @@ class RuleCollection extends CommonDBTM {
$iterator = $DB->request($criteria);
$active_tab = Session::getActiveTab($this->getType());
$can_sort = !(Toolbox::startsWith($this->getType() . '$', $active_tab));
$can_sort = !(str_starts_with($this->getType() . '$', $active_tab));
foreach ($iterator as $data) {
//For each rule, get a Rule object with all the criterias and actions
......@@ -264,7 +264,7 @@ class RuleCollection extends CommonDBTM {
if (count($iterator)) {
$this->RuleList->list = [];
$active_tab = Session::getActiveTab($this->getType());
$can_sort = !(Toolbox::startsWith($this->getType() . '$', $active_tab));
$can_sort = !(str_starts_with($this->getType() . '$', $active_tab));
foreach ($iterator as $rule) {
//For each rule, get a Rule object with all the criterias and actions
......
......@@ -663,7 +663,7 @@ class Session {
return true;
}
return Toolbox::startsWith($dir, 'core_');
return str_starts_with($dir, 'core_');
});
foreach ($core_folders as $core_folder) {
......
......@@ -72,7 +72,7 @@ class ProtectedWebAccess extends AbstractRequirement {
$check_access = false;
foreach ($this->directories as $dir) {
if (\Toolbox::startsWith($dir, GLPI_ROOT)) {
if (str_starts_with($dir, GLPI_ROOT)) {
// Only check access if one of the data directories is under GLPI document root.
$check_access = true;
break;
......
......@@ -2668,10 +2668,12 @@ class Toolbox {
* @param string $needle String to find
*
* @return boolean
*
* @deprecated 10.0.0
*/
static public function startsWith($haystack, $needle) {
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
Toolbox::deprecated('Use native str_starts_with() function.');
return str_starts_with($haystack, $needle);
}
/**
......@@ -2683,10 +2685,12 @@ class Toolbox {
* @param string $needle String to find
*
* @return boolean
*
* @deprecated 10.0.0
*/
static public function endsWith($haystack, $needle) {
$length = strlen($needle);
return $length === 0 || (substr($haystack, -$length) === $needle);
Toolbox::deprecated('Use native str_ends_with() function.');
return str_ends_with($haystack, $needle);
}
/**
......@@ -2939,7 +2943,7 @@ class Toolbox {
}
$fullpath = realpath($fullpath);
if (!Toolbox::startsWith($fullpath, realpath(GLPI_PICTURE_DIR))) {
if (!str_starts_with($fullpath, realpath(GLPI_PICTURE_DIR))) {
// Prevent deletion of a file ouside pictures directory
return false;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment