Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions php/class-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,9 @@ public static function is_admin() {
* @return array
*/
public static function extract_urls( $content ) {
// Remove inline SVG data URIs, as they can cause parsing issues when extracting URLs.
$content = self::strip_inline_svg_data_uris( $content );

preg_match_all(
"#([\"']?)("
. '(?:[\w-]+:)?//?'
Expand All @@ -642,6 +645,25 @@ public static function extract_urls( $content ) {
return array_values( $post_links );
}

/**
* Strip inline SVG data URIs from content.
*
* @param string $content The content to process.
*
* @return string The content with SVG data URIs removed.
*/
public static function strip_inline_svg_data_uris( $content ) {
// Pattern to match the data URI structure: data:image/svg+xml;base64,<base64-encoded-data>.
$svg_data_uri_pattern = '/data:image\/svg\+xml;base64,[a-zA-Z0-9\/\+\=]+/i';

// Remove all occurrences of SVG data URIs from the content.
$cleaned_content = preg_replace( $svg_data_uri_pattern, '', $content );

// In case an error occurred, we return the original content to avoid data loss.
return is_null( $cleaned_content ) ? $content : $cleaned_content;
}


/**
* Is saving metadata.
*
Expand Down