]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix crop condition 32496/head
authorCarl Schwan <carl@carlschwan.eu>
Thu, 19 May 2022 11:13:41 +0000 (13:13 +0200)
committerCarl Schwan <carl@carlschwan.eu>
Thu, 19 May 2022 15:25:32 +0000 (17:25 +0200)
Make sure that when fetching the image from the cache we don't
accidentally fetch the cropped image just because it also start with
256-256

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
lib/private/Preview/Generator.php

index a19a19ef15f6c29d50bf027eec6f4bd8be6875b4..2edea868ed0d67cc835e87b575af7f29d44caaf6 100644 (file)
@@ -144,7 +144,6 @@ class Generator {
                        && ($specifications[0]['width'] <= 256 || $specifications[0]['height'] <= 256)
                        && preg_match(Imaginary::supportedMimeTypes(), $mimeType)
                        && $this->config->getSystemValueString('preview_imaginary_url', 'invalid') !== 'invalid') {
-
                        $crop = $specifications[0]['crop'] ?? false;
                        $preview = $this->getSmallImagePreview($previewFolder, $file, $mimeType, $previewVersion, $crop);
 
@@ -233,9 +232,17 @@ class Generator {
 
                foreach ($nodes as $node) {
                        $name = $node->getName();
-                       if (($prefix === '' || strpos($name, $prefix) === 0)
-                               && (str_starts_with($name, '256-256-crop') && $crop || str_starts_with($name, '256-256') && !$crop)) {
-                               return $node;
+                       if (($prefix === '' || str_starts_with($name, $prefix))) {
+                               // Prefix match
+                               if (str_starts_with($name, $prefix . '256-256-crop') && $crop) {
+                                       // Cropped image
+                                       return $node;
+                               }
+
+                               if (str_starts_with($name, $prefix . '256-256.') && !$crop) {
+                                       // Uncropped image
+                                       return $node;
+                               }
                        }
                }