2 Commits 65f1b1e1e3 ... f1717bde51

Author SHA1 Message Date
  Miguel Dantas f1717bde51 Fix 'Call to a member function getPayload() on null' 4 years ago
  Miguel Dantas c6f4f40bba [Embed][CORE] Fixes 'Invalid Filename' on Embed. Regex didn't get updated 4 years ago
2 changed files with 7 additions and 4 deletions
  1. 6 3
      lib/media/mediafile.php
  2. 1 1
      plugins/RedisCache/RedisCachePlugin.php

+ 6 - 3
lib/media/mediafile.php

@@ -272,14 +272,17 @@ class MediaFile
      */
     public static function decodeFilename(string $encoded_filename)
     {
-        // The x is because it is using in thumbnails
-        $ret = preg_match('/^([^-x]+?)-[^-]+$/', $encoded_filename, $matches);
+        // Should match:
+        //   hex-hash
+        //   thumb-id-widthxheight-hex-hash
+        // And return the `hex` part
+        $ret = preg_match('/^(.*-)?([^-]+)-[^-]+$/', $encoded_filename, $matches);
         if ($ret === false) {
             return false;
         } elseif ($ret === 0) {
             return null; // No match
         } else {
-            $filename = hex2bin($matches[1]);
+            $filename = hex2bin($matches[2]);
 
             // Matches extension
             if (preg_match('/^(.+?)\.(.+)$/', $filename, $sub_matches) === 1) {

+ 1 - 1
plugins/RedisCache/RedisCachePlugin.php

@@ -93,7 +93,7 @@ class RedisCachePlugin extends Plugin
             return true;
         }
 
-        if (is_int($ret) || $ret->getPayload() === "OK") {
+        if (is_int($ret) || (!is_null($ret) && $ret->getPayload() === "OK")) {
             $success = true;
             return false;
         }