Enhance Gitea support by improving base64 decoding and UTF-8 encoding handling

This commit is contained in:
Matt Batchelder
2026-02-21 20:08:18 -05:00
parent 634e93236f
commit 3b51382797
4 changed files with 27 additions and 13 deletions

View File

@@ -380,13 +380,15 @@ function oribi_sync_fetch_file( string $api_base, string $branch, string $file_p
$body = wp_remote_retrieve_body( $response );
// For Gitea, the /contents/ endpoint returns base64-encoded content in JSON
// For Gitea, the /contents/ endpoint returns base64-encoded content in JSON.
// Gitea (like GitHub) inserts \n every 60 chars in the base64 — strip them before decoding.
if ( $provider === 'gitea' ) {
$decoded = json_decode( $body, true );
if ( isset( $decoded['content'] ) && is_string( $decoded['content'] ) ) {
$body = base64_decode( $decoded['content'], true );
$clean = str_replace( [ "\r", "\n", " " ], '', $decoded['content'] );
$body = base64_decode( $clean, true );
if ( $body === false ) {
return new WP_Error( 'oribi_sync_decode_error', 'Failed to decode base64 content from Gitea' );
return new WP_Error( 'oribi_sync_decode_error', 'Failed to decode base64 content from Gitea.' );
}
}
}