movim/movim

Picture: images with & in URL are broken

Closed this issue · 2 comments

dos1 commented

When a Picture tries to download an image sent as a plain link in a chat message, it gets a garbled URL that has its & characters replaced with &, leading to download failure and broken_image_filled being displayed instead of the linked image.

I haven't looked deep enough to know whether this fix is reasonable, but it does make things work:

diff --git a/app/widgets/Picture/Picture.php b/app/widgets/Picture/Picture.php
index 71047419c..512046389 100644
--- a/app/widgets/Picture/Picture.php
+++ b/app/widgets/Picture/Picture.php
@@ -10,7 +10,7 @@ class Picture extends Base
 
     public function display()
     {
-        $url = urldecode($this->get('url'));
+        $url = html_entity_decode(urldecode($this->get('url')));
         $parsedUrl = parse_url($url);
         if (
             is_array($parsedUrl)
@@ -27,7 +27,7 @@ class Picture extends Base
         $max = $headers["download_content_length"] > $this->compressLimit ? $this->compressLimit : $headers["download_content_length"];
 
         $ch = curl_init();
-        curl_setopt($ch, CURLOPT_URL, $this->get('url'));
+        curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_HEADER, true);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

I cannot reproduce the issue.
Can you give me the URL of a picture that actually have this issue ?

dos1 commented

Facebook image links like https://scontent-waw2-1.xx.fbcdn.net/v/t39.30808-6/448173070_859497432876985_184100521389069223_n.jpg?_nc_cat=101&ccb=1-7&_nc_sid=127cfc&_nc_ohc=xld4TRz6ArkQ7kNvgGVpMs6&_nc_ht=scontent-waw2-1.xx&oh=00_AYAV4DVUD8U89czrizZ9fEVVrdLRKJ6vBTyPCuBPmMXD5Q&oe=6685FA75 are good test cases.

The behavior has changed for the better since v0.24 though - such images now show up as link preview cards rather than being entirely broken. Is this expected behavior?