$version, 'package' => $package, 'url' => is_string( $url ) && self::isAllowedUrl( $url, $host ) ? $url : '', 'notes' => is_string( $release['body'] ?? null ) ? $release['body'] : '', 'published' => is_string( $release['published_at'] ?? null ) ? $release['published_at'] : '', ); } public static function normalizeVersion( mixed $tag ): ?string { if ( ! is_string( $tag ) ) { return null; } $t = trim( $tag ); if ( '' !== $t && ( 'v' === $t[0] || 'V' === $t[0] ) ) { $t = substr( $t, 1 ); } return 1 === preg_match( self::DATE_TAG, $t ) || 1 === preg_match( self::SEMVER, $t ) ? $t : null; } public static function isNewer( string $remote, string $current ): bool { $r = self::normalizeVersion( $remote ); if ( null === $r ) { return false; } return version_compare( $r, ltrim( $current, 'vV' ), '>' ); } /** https URL on exactly the configured host (no userinfo tricks). */ public static function isAllowedUrl( string $url, string $host ): bool { $p = parse_url( $url ); if ( ! is_array( $p ) || ! isset( $p['scheme'], $p['host'] ) || isset( $p['user'] ) || isset( $p['pass'] ) ) { return false; } return 'https' === strtolower( $p['scheme'] ) && '' !== $host && strtolower( $p['host'] ) === strtolower( $host ); } private static function pickPackage( array $assets, string $host ): ?string { $exact = null; $first = null; foreach ( $assets as $a ) { if ( ! is_array( $a ) || ! is_string( $a['name'] ?? null ) || ! is_string( $a['browser_download_url'] ?? null ) ) { continue; } if ( ! self::isAllowedUrl( $a['browser_download_url'], $host ) ) { continue; } if ( self::ASSET_NAME === $a['name'] ) { $exact = $exact ?? $a['browser_download_url']; } elseif ( null === $first && str_ends_with( strtolower( $a['name'] ), '.zip' ) ) { $first = $a['browser_download_url']; } } return $exact ?? $first; } /** Minimal markdown to safe HTML: everything is escaped first; only paragraphs, headings (as
' . implode( ' ', $para ) . '
'; $para = array(); } }; foreach ( $lines as $line ) { $t = trim( $line ); if ( 1 === preg_match( '/^[*\-+]\s+(.*)$/', $t, $m ) ) { $flush(); if ( ! $list ) { $out .= '