Skip to content

Commit

Permalink
Fix forcetab parameter for namespaces (#14513)
Browse files Browse the repository at this point in the history
* Fix forcetab parameter for namespaces

* Revert "Fix forcetab parameter for namespaces"

This reverts commit 4d05710.

* Fix regex that detect namespaces

* Update src/Toolbox/Sanitizer.php

---------

Co-authored-by: Cédric Anne <cedric.anne@gmail.com>
  • Loading branch information
AdrienClairembault and cedric-anne committed Apr 13, 2023
1 parent fec0b70 commit 89ffe0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Toolbox/Sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public static function isDbEscaped(string $value): bool

/**
* Check wether the value correspond to a valid namespaced class (or a callable identifier related to a valid class).
* Note: also support the {namespace}${tab number} format used for tab identifications
*
* @param string $value
*
Expand All @@ -227,8 +228,12 @@ public static function isDbEscaped(string $value): bool
public static function isNsClassOrCallableIdentifier(string $value): bool
{
$class_match = [];
return preg_match('/^(?<class>(([a-zA-Z0-9_]+\\\)+[a-zA-Z0-9_]+))(:?:[a-zA-Z0-9_]+)?$/', $value, $class_match)
&& class_exists($class_match['class']);

return preg_match(
'/^(?<class>(([a-zA-Z0-9_]+\\\)+[a-zA-Z0-9_]+))(:?:[a-zA-Z0-9_]+)?(\$[0-9]+)?$/',
$value,
$class_match
) && class_exists($class_match['class']);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/units/Glpi/Toolbox/Sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@ protected function isNsClassOrCallableIdentifierProvider(): iterable
'value' => 'Glpi\\\\Socket',
'is_class' => false, // namespace separator are escaped, so it is not considered as a valid classname
];
yield [
'value' => 'Glpi\Dashboard\Dashboard$1',
'is_class' => true, // special format for tab names
];
}

/**
Expand Down

0 comments on commit 89ffe0f

Please sign in to comment.