From 0763608eba68c85dd7a8573e6a93a75c3c841345 Mon Sep 17 00:00:00 2001 From: Leonidas Milosis Date: Fri, 13 Sep 2024 10:31:02 +0300 Subject: [PATCH] Make regex case insensitive and not considering matches in the middle of filenames and unify them --- src/helpers/schema/image-helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/schema/image-helper.php b/src/helpers/schema/image-helper.php index 59065138766..9ca5d8b56a2 100644 --- a/src/helpers/schema/image-helper.php +++ b/src/helpers/schema/image-helper.php @@ -61,7 +61,7 @@ public function generate_from_url( $schema_id, $url, $caption = '', $add_hash = $attachment_id = $this->image->get_attachment_by_url( $url, $use_link_table ); if ( $attachment_id > 0 ) { // First check if we should use the resized image and whether it is a resized image indeed. - if ( $check_for_resized && \preg_match( '/-\d+x\d+\.(jpg|jpeg|png|gif|webp)$/i', $url ) ) { + if ( $check_for_resized && \preg_match( '/-(\d+)x(\d+)\.(jpg|jpeg|png|gif|webp)$/', $url ) ) { return $this->generate_from_resized_url( $schema_id, $attachment_id, $caption, $add_hash, $url ); } @@ -91,7 +91,7 @@ public function generate_from_resized_url( $schema_id, $attachment_id, $caption $data['url'] = $resized_url; $data['contentUrl'] = $resized_url; - \preg_match( '/-(\d+)x(\d+)\.(jpg|jpeg|png|gif|webp)/', $resized_url, $matches ); + \preg_match( '/-(\d+)x(\d+)\.(jpg|jpeg|png|gif|webp)$/', $resized_url, $matches ); $data['width'] = $matches[1]; $data['height'] = $matches[2];