From c172969e527e274ea1f93a56c0ffa46c3f236898 Mon Sep 17 00:00:00 2001 From: sksaju Date: Tue, 13 Feb 2024 02:33:39 +0600 Subject: [PATCH 1/3] fix width and height metadata condtion on svg_dimensions function --- safe-svg.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/safe-svg.php b/safe-svg.php index af20563..bf7b1c4 100644 --- a/safe-svg.php +++ b/safe-svg.php @@ -591,7 +591,7 @@ protected function svg_dimensions( $attachment_id ) { $width = 0; $height = 0; - if ( $svg && ! empty( $metadata['width'] ) && empty( $metadata['height'] ) ) { + if ( $svg && ! empty( $metadata['width'] ) && ! empty( $metadata['height'] ) ) { $width = floatval( $metadata['width'] ); $height = floatval( $metadata['height'] ); } elseif ( $svg ) { From 822f8db48410eb71e660e9b51cc254b10290a475 Mon Sep 17 00:00:00 2001 From: sksaju Date: Tue, 13 Feb 2024 03:19:53 +0600 Subject: [PATCH 2/3] fix php unit test issue --- tests/unit/test-safe-svg.php | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/unit/test-safe-svg.php b/tests/unit/test-safe-svg.php index ab56eae..86ad2e0 100644 --- a/tests/unit/test-safe-svg.php +++ b/tests/unit/test-safe-svg.php @@ -262,6 +262,53 @@ public function test_one_pixel_fix() { ), ), ), + array( + 'file' => __DIR__ . '/files/svgNoDimensions.svg', + 'sizes' => array( + 'thumbnail' => array( + 'width' => 150, + 'height' => 150, + 'crop' => 1, + 'file' => 'svgNoDimensions.svg', + 'mime-type' => 'image/svg+xml', + ), + 'medium' => array( + 'width' => 300, + 'height' => 300, + 'crop' => 0, // Set to 0 if you don't want to crop + 'file' => 'svgNoDimensions.svg', + 'mime-type' => 'image/svg+xml', + ), + 'medium_large' => array( + 'width' => 768, + 'height' => 0, + 'crop' => 0, + 'file' => 'svgNoDimensions.svg', + 'mime-type' => 'image/svg+xml', + ), + 'large' => array( + 'width' => 1024, + 'height' => 1024, + 'crop' => 0, + 'file' => 'svgNoDimensions.svg', + 'mime-type' => 'image/svg+xml', + ), + '1536x1536' => array( + 'width' => 1536, + 'height' => 1536, + 'crop' => 0, + 'file' => 'svgNoDimensions.svg', + 'mime-type' => 'image/svg+xml', + ), + '2048x2048' => array( + 'width' => 2048, + 'height' => 2048, + 'crop' => 0, + 'file' => 'svgNoDimensions.svg', + 'mime-type' => 'image/svg+xml', + ), + ), + ), ), ) ); From 5900612c4a48ae2545a416dd108ffe9fda7249ad Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Tue, 19 Mar 2024 17:41:40 +0530 Subject: [PATCH 3/3] Update mocked response for the `wp_get_attachment_metadata` function in unit tests. --- tests/unit/test-safe-svg.php | 46 +----------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/tests/unit/test-safe-svg.php b/tests/unit/test-safe-svg.php index 86ad2e0..4b52f6e 100644 --- a/tests/unit/test-safe-svg.php +++ b/tests/unit/test-safe-svg.php @@ -263,51 +263,7 @@ public function test_one_pixel_fix() { ), ), array( - 'file' => __DIR__ . '/files/svgNoDimensions.svg', - 'sizes' => array( - 'thumbnail' => array( - 'width' => 150, - 'height' => 150, - 'crop' => 1, - 'file' => 'svgNoDimensions.svg', - 'mime-type' => 'image/svg+xml', - ), - 'medium' => array( - 'width' => 300, - 'height' => 300, - 'crop' => 0, // Set to 0 if you don't want to crop - 'file' => 'svgNoDimensions.svg', - 'mime-type' => 'image/svg+xml', - ), - 'medium_large' => array( - 'width' => 768, - 'height' => 0, - 'crop' => 0, - 'file' => 'svgNoDimensions.svg', - 'mime-type' => 'image/svg+xml', - ), - 'large' => array( - 'width' => 1024, - 'height' => 1024, - 'crop' => 0, - 'file' => 'svgNoDimensions.svg', - 'mime-type' => 'image/svg+xml', - ), - '1536x1536' => array( - 'width' => 1536, - 'height' => 1536, - 'crop' => 0, - 'file' => 'svgNoDimensions.svg', - 'mime-type' => 'image/svg+xml', - ), - '2048x2048' => array( - 'width' => 2048, - 'height' => 2048, - 'crop' => 0, - 'file' => 'svgNoDimensions.svg', - 'mime-type' => 'image/svg+xml', - ), - ), + 'filesize' => 1001, // wp_get_attachment_metadata response for ./files/svgNoDimensions.svg file doesn't contain dimensions and sizes array. ), ), )