Browse Source

Fix raw.github.com images by using raw.githack.com proxy, fixes #929

Jordi Boggiano 6 years ago
parent
commit
8cb38005b1

+ 1 - 0
app/config/config_prod.yml

@@ -97,6 +97,7 @@ nelmio_security:
                 - 'https://www.gravatar.com/'
                 - 'https://*.githubusercontent.com'
                 - 'https://raw.github.com/'
+                - 'https://rawcdn.githack.com/'
                 - 'https://github.com/'
                 - 'https://gitlab.com/'
                 - 'https://www.google-analytics.com/'

+ 10 - 0
src/Packagist/WebBundle/Entity/Package.php

@@ -484,6 +484,16 @@ class Package
         return $this->readme;
     }
 
+    /**
+     * Get readme with transformations that should not be done in the stored readme as they might not be valid in the long run
+     *
+     * @return string
+     */
+    public function getOptimizedReadme()
+    {
+        return str_replace(['<img src="https://raw.github.com/', '<img src="https://raw.githubusercontent.com/'], '<img src="https://rawcdn.githack.com/', $this->readme);
+    }
+
     /**
      * @param int $val
      */

+ 1 - 1
src/Packagist/WebBundle/Resources/views/Package/viewPackage.html.twig

@@ -276,7 +276,7 @@
             <hr class="clearfix">
             <div class="readme markdown-body">
                 <h1>README</h1>
-                {{ package.readme|raw }}
+                {{ package.optimizedReadme|raw }}
             </div>
         {% endif %}
     </div>