diff --git a/src/Std/Lib/Activitypub.php b/src/Std/Lib/Activitypub.php
index 127eb00..196bb63 100644
--- a/src/Std/Lib/Activitypub.php
+++ b/src/Std/Lib/Activitypub.php
@@ -39,6 +39,7 @@ namespace Std\Lib;
use Std\Lib\Curl;
use LogType;
+use Uri\Rfc3986;
/**
* ActivityPubプロトコルの実装クラス
@@ -445,10 +446,10 @@ class ActivityPub {
$body = json_encode($activity, JSON_UNESCAPED_SLASHES);
$digest = base64_encode(hash('sha256', $body, true));
$date = gmdate('D, d M Y H:i:s \G\M\T');
- $host = parse_url($inboxUrl, PHP_URL_HOST);
+ $uri = new Uri($inboxUrl);
$headers = [
- 'Host' => $host,
+ 'Host' => $uri->getHost().($uri->getPort() ? ':'.$uri->getPort() : ''),
'Date' => $date,
'Content-Type' => 'application/activity+json',
'Digest' => "SHA-256=$digest",
diff --git a/src/Std/Lib/Curl.php b/src/Std/Lib/Curl.php
index 819e447..043b77f 100644
--- a/src/Std/Lib/Curl.php
+++ b/src/Std/Lib/Curl.php
@@ -38,6 +38,7 @@ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
namespace Std\Lib;
use Result;
+use Uri\Rfc3986;
/**
* php_curlへの依存を排除するための独自のCURL実装
@@ -354,19 +355,18 @@ class Curl {
fwrite($this->stderr, "* 接続中: {$currentUrl}\n");
}
- $parsed = parse_url($currentUrl);
- if (!$parsed) {
+ $uri = new Uri($currentUrl);
+ if (!$uri) {
$this->responseError = "無効なURL: {$currentUrl}";
return Result::Error($this->responseError);
}
- $scheme = isset($parsed['scheme']) ? strtolower($parsed['scheme']) : 'http';
- $host = $parsed['host'];
- $port = isset($parsed['port'])
- ? $parsed['port'] : ($scheme === 'https' ? 443 : 80);
- $path = isset($parsed['path']) ? $parsed['path'] : '/';
- if (isset($parsed['query'])) {
- $path .= '?'.$parsed['query'];
+ $scheme = $uri->getScheme() ?? 'http';
+ $port = $uri->getPort() ?? ($scheme === 'https' ? 443 : 80);
+ $path = $uri->getPath();
+ if ($path === '') $path = '/';
+ if (isset($uri->getQuery())) {
+ $path .= '?'.$uri->getQuery();
}
// 認証
@@ -404,7 +404,7 @@ class Curl {
}
$request = "{$method} {$path} HTTP/1.1\r\n";
- $request .= "Host: {$host}\r\n";
+ $request .= "Host: {$uri->getHost()}\r\n";
$request .= "User-Agent: {$this->userAgent}\r\n";
$request .= "{$accept}\r\n";
$request .= "Connection: close\r\n";
@@ -462,7 +462,7 @@ class Curl {
$context = stream_context_create(['ssl' => $sslOptions]);
$socket = @stream_socket_client(
- "tls://{$host}:{$port}",
+ "tls://{$uri->getHost()}:{$port}",
$errno,
$errstr,
$this->timeout,
@@ -470,7 +470,7 @@ class Curl {
$context
);
} else {
- $socket = @fsockopen($host, $port, $errno, $errstr, $this->timeout);
+ $socket = @fsockopen($uri->getHost(), $port, $errno, $errstr, $this->timeout);
}
if (!$socket) {
@@ -637,9 +637,9 @@ class Curl {
if (strpos($redirectUrl, 'http') !== 0) {
if ($redirectUrl[0] === '/') {
- $parsed = parse_url($currentUrl);
- $redirectUrl = $parsed['scheme'].'://'.$parsed['host']
- .(isset($parsed['port']) ? ':'.$parsed['port'] : '')
+ $uri = new Uri($currentUrl);
+ $redirectUrl = $uri->getScheme().'://'.$uri->getHost()
+ .(isset($uri->getPort()) ? ':'.$uri->getPort() : '')
.$redirectUrl;
} else {
$redirectUrl = dirname($currentUrl).'/'.$redirectUrl;
diff --git a/src/Std/Lib/Tester.php b/src/Std/Lib/Tester.php
index 90e9be9..35359de 100644
--- a/src/Std/Lib/Tester.php
+++ b/src/Std/Lib/Tester.php
@@ -407,6 +407,7 @@ class Tester {
*/
public function assertArrayHasKey(mixed $key, array $array,
?string $message = null): Tester {
+ if (NULL === $key) throw new AssertionFailedException("配列鍵がありません");
if (!is_array($array) && !($array instanceof \ArrayAccess)) {
throw new AssertionFailedException(
'第2引数は配列又はArrayAccessを実装している必要があります');
diff --git a/util.php b/util.php
index d1236c3..f09bed0 100644
--- a/util.php
+++ b/util.php
@@ -470,11 +470,4 @@ function align_down(int $val): int {
while ($lower * 2 <= $val) $lower *= 2;
return $lower;
-}
-
-// PHP 8.3と8.4の場合
-if (!function_exists('array_last')) {
- function array_last(array $array): mixed {
- return $array === [] ? null : $array[array_key_last($array)];
- }
}
\ No newline at end of file
diff --git a/view/common/header.maron b/view/common/header.maron
index d3e96b3..9b88a36 100644
--- a/view/common/header.maron
+++ b/view/common/header.maron
@@ -20,7 +20,7 @@
{@ endif @}
{@ endif @}
-
+