@@ -92,6 +92,7 @@ public function search(string &$uid, bool $matchUid = false): string {
9292 * @throws \Exception
9393 */
9494 protected function queryLookupServer (string $ uid , bool $ matchUid = false ) {
95+ $ this ->sanitizeUid ($ uid );
9596 $ this ->logger ->debug ('queryLookupServer: asking lookup server for: ' . $ uid . ' (matchUid: ' . json_encode ($ matchUid ) . ') ' );
9697 $ client = $ this ->clientService ->newClient ();
9798 $ response = $ client ->get (
@@ -110,7 +111,7 @@ protected function queryLookupServer(string $uid, bool $matchUid = false) {
110111 return json_decode ($ response ->getBody (), true );
111112 }
112113
113- protected function getUserLocation (string $ address , string &$ uid = '' ): string {
114+ public function getUserLocation (string $ address , string &$ uid = '' ): string {
114115 try {
115116 return match ($ this ->config ->getSystemValueString ('gss.username_format ' , 'validate ' )) {
116117 'ignore ' => $ this ->getUserLocation_Ignore ($ address ),
@@ -161,32 +162,39 @@ private function getUserLocation_Ignore(string $address, ?string &$uid = ''): st
161162 */
162163 private function getUserLocation_Sanitize (string $ address , string &$ uid ): string {
163164 $ address = $ this ->getUserLocation_Ignore ($ address , $ extractedUid );
164- $ extractedUid = htmlentities ($ extractedUid , ENT_NOQUOTES , 'UTF-8 ' );
165+ $ this ->sanitizeUid ($ extractedUid );
166+ $ uid = $ extractedUid ;
167+
168+ return $ address ;
169+ }
170+
171+
172+ public function sanitizeUid (string &$ uid = '' ): void {
173+ if ($ this ->config ->getSystemValueString ('gss.username_format ' , '' ) !== 'sanitize ' ) {
174+ return ;
175+ }
165176
166- $ extractedUid = preg_replace (
167- '#&([A-Za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);# ' , '\1 ' , $ extractedUid
177+ $ uid = htmlentities ($ uid , ENT_NOQUOTES , 'UTF-8 ' );
178+
179+ $ uid = preg_replace (
180+ '#&([A-Za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);# ' , '\1 ' , $ uid
168181 );
169- $ extractedUid = preg_replace ('#&([A-Za-z]{2})(?:lig);# ' , '\1 ' , $ extractedUid );
170- $ extractedUid = preg_replace ('#&[^;]+;# ' , '' , $ extractedUid );
171- $ extractedUid = str_replace (' ' , '_ ' , $ extractedUid );
172- $ extractedUid = preg_replace ('/[^a-zA-Z0-9_.@-]/u ' , '' , $ extractedUid );
182+ $ uid = preg_replace ('#&([A-Za-z]{2})(?:lig);# ' , '\1 ' , $ uid );
183+ $ uid = preg_replace ('#&[^;]+;# ' , '' , $ uid );
184+ $ uid = str_replace (' ' , '_ ' , $ uid );
185+ $ uid = preg_replace ('/[^a-zA-Z0-9_.@-]/u ' , '' , $ uid );
173186
174- if (strlen ($ extractedUid ) > 64 ) {
175- $ extractedUid = hash ('sha256 ' , $ extractedUid , false );
187+ if (strlen ($ uid ) > 64 ) {
188+ $ uid = hash ('sha256 ' , $ uid , false );
176189 }
177190
178- if ($ extractedUid === '' ) {
191+ if ($ uid === '' ) {
179192 throw new \InvalidArgumentException (
180193 'provided name template for username does not contain any allowed characters '
181194 );
182195 }
183-
184- $ uid = $ extractedUid ;
185-
186- return $ address ;
187196 }
188197
189-
190198 /**
191199 * @param array $options
192200 *
0 commit comments