Fix ACLFormatterTest
- Add nullable to expand() function again - Add angle bracket support to toString()
This commit is contained in:
parent
bc18cde412
commit
aa7be41728
6 changed files with 51 additions and 24 deletions
|
@ -12,12 +12,17 @@ final class ACLFormatter
|
|||
/**
|
||||
* Turn user/group ACLs stored as angle bracketed text into arrays
|
||||
*
|
||||
* @param string $ids A angle-bracketed list of IDs
|
||||
* @param string|null $ids A angle-bracketed list of IDs
|
||||
*
|
||||
* @return array The array based on the IDs
|
||||
* @return array|null The array based on the IDs (null in case there is no list)
|
||||
*/
|
||||
public function expand(string $ids)
|
||||
public function expand(string $ids = null)
|
||||
{
|
||||
// In case there is no ID list, return null (=> no ACL set)
|
||||
if (!isset($ids)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// turn string array of angle-bracketed elements into numeric array
|
||||
// e.g. "<1><2><3>" => array(1,2,3);
|
||||
preg_match_all('/<(' . Group::FOLLOWERS . '|'. Group::MUTUALS . '|[0-9]+)>/', $ids, $matches, PREG_PATTERN_ORDER);
|
||||
|
@ -31,12 +36,18 @@ final class ACLFormatter
|
|||
* @param string $item The item to sanitise
|
||||
*/
|
||||
private function sanitize(string &$item) {
|
||||
// The item is an ACL int value
|
||||
if (intval($item)) {
|
||||
$item = '<' . intval(Strings::escapeTags(trim($item))) . '>';
|
||||
// The item is a allowed ACL character
|
||||
} elseif (in_array($item, [Group::FOLLOWERS, Group::MUTUALS])) {
|
||||
$item = '<' . $item . '>';
|
||||
} else {
|
||||
// The item is already a ACL string
|
||||
} elseif (preg_match('/<\d+?>/', $item)) {
|
||||
unset($item);
|
||||
// The item is not supported, so remove it (cleanup)
|
||||
} else {
|
||||
$item = '';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue