]> BookStack Code Mirror - bookstack/blobdiff - app/Auth/Access/GroupSyncService.php
Guest create page: name field autofocus
[bookstack] / app / Auth / Access / GroupSyncService.php
index ddd539b7773ac01c73ebe658703b234ea0a130ec..37d4e02d0b12fb980b3376ce2b958c903027cc5b 100644 (file)
@@ -28,10 +28,8 @@ class GroupSyncService
      */
     protected function externalIdMatchesGroupNames(string $externalId, array $groupNames): bool
     {
-        $externalAuthIds = explode(',', strtolower($externalId));
-
-        foreach ($externalAuthIds as $externalAuthId) {
-            if (in_array(trim($externalAuthId), $groupNames)) {
+        foreach ($this->parseRoleExternalAuthId($externalId) as $externalAuthId) {
+            if (in_array($externalAuthId, $groupNames)) {
                 return true;
             }
         }
@@ -39,6 +37,18 @@ class GroupSyncService
         return false;
     }
 
+    protected function parseRoleExternalAuthId(string $externalId): array
+    {
+        $inputIds = preg_split('/(?<!\\\),/', strtolower($externalId));
+        $cleanIds = [];
+
+        foreach ($inputIds as $inputId) {
+            $cleanIds[] = str_replace('\,', ',', trim($inputId));
+        }
+
+        return $cleanIds;
+    }
+
     /**
      * Match an array of group names to BookStack system roles.
      * Formats group names to be lower-case and hyphenated.
@@ -73,4 +83,4 @@ class GroupSyncService
             $user->roles()->syncWithoutDetaching($groupsAsRoles);
         }
     }
-}
\ No newline at end of file
+}