Skip to content

Commit

Permalink
Don't rewrite data URLs (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk authored Feb 12, 2025
1 parent 9b0d8b6 commit ec5aa4f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions feed-parsers/class-feed-parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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] );
},
Expand Down

0 comments on commit ec5aa4f

Please sign in to comment.