Skip to content

Commit

Permalink
Fix image links on private-user-images, fixes #1467
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Oct 3, 2024
1 parent 81fb179 commit 2e2949c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/HtmlSanitizer/ReadmeImageSanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function sanitizeAttribute(string $element, string $attribute, string $va
}

if (str_starts_with($value, 'https://private-user-images.githubusercontent.com/')) {
return Preg::replace('{^https://private-}', 'https://', $value, 1);
return Preg::replace('{^https://private-user-images.githubusercontent.com/\d+/\d+-([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})\.\w+\?.*$}', 'https://github.com/user-attachments/assets/$1', $value, 1);
}

return $value;
Expand Down
5 changes: 5 additions & 0 deletions src/HtmlSanitizer/ReadmeLinkSanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\HtmlSanitizer;

use Composer\Pcre\Preg;
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;
use Symfony\Component\HtmlSanitizer\Visitor\AttributeSanitizer\AttributeSanitizerInterface;

Expand Down Expand Up @@ -59,6 +60,10 @@ public function sanitizeAttribute(string $element, string $attribute, string $va
return 'https://gitlab.com/'.$this->ownerRepo.'/-/blob/HEAD/'.$this->basePath.$value;
}

if (str_starts_with($value, 'https://private-user-images.githubusercontent.com/')) {
return Preg::replace('{^https://private-user-images.githubusercontent.com/\d+/\d+-([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})\.\w+\?.*$}', 'https://github.com/user-attachments/assets/$1', $value, 1);
}

return $value;
}
}

0 comments on commit 2e2949c

Please sign in to comment.