From 5875affd5394f546c3744af8b2dd58a4645ee54d Mon Sep 17 00:00:00 2001 From: Adrien Dorsaz Date: Sat, 23 Mar 2024 01:18:37 +0100 Subject: [PATCH] URI.encode has been removed from Ruby 3 Image caching were not working because the Image model silently decided all image were "internal": the URI.encode (aka URI.escape) method does not exist anymore in Ruby 3, which raised an error which where ignored by the "rescue" line. Instead of doing "URI.parse(URI.encode(str))", we are just doing "URI.join(str)", because the join method converts firt the str to RFC3986. As this method does not raise error, the "rescue" part has been removed too. --- app/models/image.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/models/image.rb b/app/models/image.rb index eb898dce..ffd826fe 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -46,14 +46,12 @@ def register_in_redis end def internal_link? - uri = URI.parse(URI.encode link) + uri = URI.join(link) !uri.host || uri.host == MY_DOMAIN || uri.host == IMG_DOMAIN - rescue - true end def blacklisted? - uri = URI.parse(URI.encode link) + uri = URI.join(link) uri.host =~ /^(10|127|169\.254|192\.168)\./ end