From ec5aa4f86e7f46aee4b40d1f59505a17da8f2ad5 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 12 Feb 2025 14:59:17 +0100 Subject: [PATCH] Don't rewrite data URLs (#467) --- feed-parsers/class-feed-parser.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/feed-parsers/class-feed-parser.php b/feed-parsers/class-feed-parser.php index 2c740588..fe13b5ed 100644 --- a/feed-parsers/class-feed-parser.php +++ b/feed-parsers/class-feed-parser.php @@ -94,16 +94,21 @@ public function convert_relative_urls_to_absolute_urls( $html, $permalink ) { return preg_replace_callback( '~(src|href)=(?:"([^"]+)|\'([^\']+))~i', function ( $m ) use ( $permalink ) { + // Don't update hash-only links. if ( str_starts_with( $m[2], '#' ) ) { - // Don't update hash-only links. return $m[0]; } + // Remove absolute URL from hashes so that it can become relative. if ( str_starts_with( $m[2], $permalink . '#' ) ) { - // Remove absolute URL from hashes. return str_replace( $permalink, '', $m[0] ); } + // Don't convert content URLs like data:image/png;base64, etc. + if ( str_starts_with( $m[2], 'data:' ) ) { + return $m[0]; + } + // Convert relative URLs to absolute ones. return str_replace( $m[2], Mf2\resolveUrl( $permalink, $m[2] ), $m[0] ); },