From 6b6599186784b3aeb99026dca0ab0bf56be52a5b Mon Sep 17 00:00:00 2001 From: Chad Sikorra Date: Sun, 13 Oct 2024 13:11:38 -0400 Subject: [PATCH 1/5] Add PHP 8.3 to CI runs. --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cb4080e1..9da4631a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest, windows-latest] - php-versions: ['8.1', '8.2'] + php-versions: ['8.1', '8.2', '8.3'] name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} steps: - name: Checkout From 1bf2b2c7a46d6833da711b0dff1ee9682831ef02 Mon Sep 17 00:00:00 2001 From: Chad Sikorra Date: Sun, 13 Oct 2024 13:16:19 -0400 Subject: [PATCH 2/5] More narrowly define the string types for the transport option. --- src/FreeDSx/Ldap/ClientOptions.php | 6 ++++++ src/FreeDSx/Ldap/ServerOptions.php | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/FreeDSx/Ldap/ClientOptions.php b/src/FreeDSx/Ldap/ClientOptions.php index a56c18ea..7d47ca6d 100644 --- a/src/FreeDSx/Ldap/ClientOptions.php +++ b/src/FreeDSx/Ldap/ClientOptions.php @@ -26,6 +26,9 @@ final class ClientOptions private int $port = 389; + /** + * @var 'tcp'|'udp'|'unix' + */ private string $transport = 'tcp'; private ?string $baseDn = null; @@ -127,6 +130,9 @@ public function getTransport(): string return $this->transport; } + /** + * @param 'tcp'|'udp'|'unix' $transport + */ public function setTransport(string $transport): self { $this->transport = $transport; diff --git a/src/FreeDSx/Ldap/ServerOptions.php b/src/FreeDSx/Ldap/ServerOptions.php index 3deff27f..92eced48 100644 --- a/src/FreeDSx/Ldap/ServerOptions.php +++ b/src/FreeDSx/Ldap/ServerOptions.php @@ -27,6 +27,9 @@ final class ServerOptions private string $unixSocket = '/var/run/ldap.socket'; + /** + * @var 'tcp'|'udp'|'unix' + */ private string $transport = 'tcp'; private int $idleTimeout = 600; @@ -105,6 +108,9 @@ public function getTransport(): string return $this->transport; } + /** + * @param 'tcp'|'udp'|'unix' $transport + */ public function setTransport(string $transport): self { $this->transport = $transport; From 728d66da6f7dc09c2d21f60a42c7989a2af04fd9 Mon Sep 17 00:00:00 2001 From: Chad Sikorra Date: Sun, 13 Oct 2024 13:44:33 -0400 Subject: [PATCH 3/5] More careful handling of regex matches from LDAP url parsing. --- src/FreeDSx/Ldap/LdapUrl.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/FreeDSx/Ldap/LdapUrl.php b/src/FreeDSx/Ldap/LdapUrl.php index 5a22e039..5aa9ee6b 100644 --- a/src/FreeDSx/Ldap/LdapUrl.php +++ b/src/FreeDSx/Ldap/LdapUrl.php @@ -269,22 +269,23 @@ private static function explodeUrl(string $url): array } $query = null; $path = null; + $raw_path = $matches[2] ?? null; # Check for query parameters but no path... - if (strlen($matches[2]) > 0 && $matches[2][0] === '?') { - $query = substr($matches[2], 1); + if (is_string($raw_path) && strlen($raw_path) > 0 && $raw_path[0] === '?') { + $query = substr($raw_path, 1); # Check if there are any query parameters and a possible path... - } elseif (str_contains($matches[2], '?')) { - $parts = explode('?', $matches[2], 2); + } elseif (is_string($raw_path) && str_contains($raw_path, '?')) { + $parts = explode('?', $raw_path, 2); $path = $parts[0]; $query = $parts[1] ?? null; # A path only... } else { - $path = $matches[2]; + $path = $raw_path; } $pieces = [ - 'scheme' => $matches[1], + 'scheme' => $matches[1] ?? null, 'path' => $path, 'query' => $query, ]; From cf8c54eb66a7ba0e8edd1d0667f2a6b7640a1370 Mon Sep 17 00:00:00 2001 From: Chad Sikorra Date: Sun, 13 Oct 2024 13:47:33 -0400 Subject: [PATCH 4/5] Account for a potentially null url scheme. --- src/FreeDSx/Ldap/LdapUrl.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/FreeDSx/Ldap/LdapUrl.php b/src/FreeDSx/Ldap/LdapUrl.php index 5aa9ee6b..5503596f 100644 --- a/src/FreeDSx/Ldap/LdapUrl.php +++ b/src/FreeDSx/Ldap/LdapUrl.php @@ -290,7 +290,9 @@ private static function explodeUrl(string $url): array 'query' => $query, ]; } - $pieces['scheme'] = strtolower($pieces['scheme']); + $pieces['scheme'] = isset($pieces['scheme']) + ? strtolower($pieces['scheme']) + : null; if (!($pieces['scheme'] === 'ldap' || $pieces['scheme'] === 'ldaps')) { throw new UrlParseException(sprintf( From bc5a10c55707e144372392fbd355de5c7a3b7785 Mon Sep 17 00:00:00 2001 From: Chad Sikorra Date: Sun, 13 Oct 2024 13:55:38 -0400 Subject: [PATCH 5/5] Fix return types. --- src/FreeDSx/Ldap/LdapUrl.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/FreeDSx/Ldap/LdapUrl.php b/src/FreeDSx/Ldap/LdapUrl.php index 5503596f..58ee3041 100644 --- a/src/FreeDSx/Ldap/LdapUrl.php +++ b/src/FreeDSx/Ldap/LdapUrl.php @@ -254,7 +254,7 @@ public static function parse(string $ldapUrl): LdapUrl } /** - * @return array{scheme: ?string, path: ?string, query: ?string, host: ?string, port: ?string} + * @return array{scheme: 'ldap'|'ldaps', host?: string, port?: int<0, 65535>, user?: string, pass?: string, path?: ?string, query?: ?string, fragment?: string} * @throws UrlParseException */ private static function explodeUrl(string $url): array @@ -292,7 +292,7 @@ private static function explodeUrl(string $url): array } $pieces['scheme'] = isset($pieces['scheme']) ? strtolower($pieces['scheme']) - : null; + : ''; if (!($pieces['scheme'] === 'ldap' || $pieces['scheme'] === 'ldaps')) { throw new UrlParseException(sprintf( @@ -301,7 +301,6 @@ private static function explodeUrl(string $url): array )); } - /** @phpstan-ignore-next-line */ return $pieces; }