Commit 01a37cd6 authored by Stephen Mulvihill's avatar Stephen Mulvihill Committed by Fabian de Rijk
Browse files

Issue #3285277 by smulvih2: Illegal characters in displayName

parent 9728d306
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ class UserLoginController extends ControllerBase {
    // If we haven't found an account to link, create one from the data.
    if (!$account) {
      $accountData = [
        'name' => $userData['displayName'],
        'name' => $this->sanitizeUsername($userData['displayName']),
        'mail' => $userData['userPrincipalName'],
      ];
      $account = $this->externalAuth->register($o365_id, 'o365_sso', $accountData);
@@ -135,4 +135,19 @@ class UserLoginController extends ControllerBase {
    return new RedirectResponse($redirectUrl);
  }

  /**
   * Sanitize username.
   *
   * @param string $username
   *   The username coming from o365.
   *
   * @return string $username
   *   The sanitized username.
   */
  public function sanitizeUsername($username) {
    // Strip illegal characters.
    $username = preg_replace('/[^\\x{80}-\\x{F7} a-zA-Z0-9@_.\'-]/', '', $username);
    return $username;
  }

}