SF.net SVN: phpwiki:[10910] trunk/lib/stdlib.php

vargenau--- via phpwiki-checkins <[email protected]> Thu, 20 Jan 2022 10:00:37 +0000
Newsgroups gmane.comp.web.wiki.phpwiki.checkins
Message-ID <[email protected]>
Revision: 10910
          http://sourceforge.net/p/phpwiki/code/10910
Author:   vargenau
Date:     2022-01-20 10:00:37 +0000 (Thu, 20 Jan 2022)
Log Message:
-----------
Better handle images with space in the filename

Modified Paths:
--------------
    trunk/lib/stdlib.php

Modified: trunk/lib/stdlib.php
===================================================================
--- trunk/lib/stdlib.php	2022-01-19 14:40:36 UTC (rev 10909)
+++ trunk/lib/stdlib.php	2022-01-20 10:00:37 UTC (rev 10910)
@@ -415,8 +415,17 @@
         $alt = "";
     }
     // Extract URL
-    $arr = explode(' ', $url);
-    if (!empty($arr)) $url = $arr[0];
+    // Space might be part of the filename, or separate the filename and the attributes
+    // [[Upload:raton laveur.jpg]] here the $url ends with an image extension, so space is part of the filename
+    // [[Upload:sanglier.jpg size=20% align=right]] here the space separates the filename and the attributes
+    // [[Upload:raton laveur.jpg size=20% align=right]] will fail
+    // It should be encoded as [[Upload:admin/raton%20laveur.jpg size=20% align=right]]
+    if (!is_image($url)) {
+        $arr = explode(' ', $url);
+        if (!empty($arr)) {
+            $url = $arr[0];
+        }
+    }
     if (!IsSafeURL($url)) {
         return HTML::span(array('class' => 'error'), _('Bad URL for image').' -- '._('Remove all of <, >, "'));
     }

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.